Reputation: 39
I have a form that contains a checkbox
when I add [(ngModel)]
to the tag, the checkbox will be automatically checked when the page load
<input type="checkbox" name="test" id="test" [(ngModel)]="model.test" value="1"> test
I tried to fix this using
ngOnInit() {
let test = document.getElementById('test') as HTMLInputElement;
test.checked = false;
}
in the .ts but didn't work
is there any way I can make the checkbox unchecked in the loading of the page?
Upvotes: 1
Views: 3712
Reputation: 1846
The problem is your model, use:
model.text = false;
But in normal model must be:
let model = [
{id: 1, label: "Check 1", checked: false},
{id: 2, label: "Check 2", checked: false},
{id: 3, label: "Check 3", checked: false}
];
Upvotes: 3