user3504563
user3504563

Reputation: 39

Angular: Uncheck Checkbox With [(ngModel)]

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

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222532

You can just use

this.model.text = false;

Upvotes: 1

Carnaru Valentin
Carnaru Valentin

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

Related Questions