I have my input below:
<input class="form-check-input" type="checkbox" [name]="myCheck">
I want to get the element in TypeScript file and change in it some sort of like:
document.getElementByName("myCheck").checked = true;
But the ‘checked’ property is not recognizable.
So how should I proceed?
>Solution :
You’re using getElementByName, but that’s not a valid function. It should be getElementsByName and then give a valid index.
You can also use querySelector("[name='myCheck']").
As for typescript:
You first have to let typescript know what the element exactly is:
const checkboxEl = document.getElementsByName("myCheck")[0] as HTMLInputElement;
checkboxEl.checked = true;