1

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?

2 Answers 2

3

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}
];
Sign up to request clarification or add additional context in comments.

Comments

1

You can just use

this.model.text = false;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.