I have a checkbox that I need the value to reflect the boolean in the data model and disregard attempts by the user to change it.
Here is an example of my setup:
Data model
const item = {label: 'test', active: false, selected: false};
Template with various inputs I have tried:
<li (click)="item.selected = !item.selected" [class.selected]="item.selected">
<input type="checkbox" [ngModel]="item.active">
<input type="checkbox" [value]="item.active">
<input type="checkbox" [checked]="item.active">
{{item.label}}
</li>
Since the active state in the data is not being changed (not 2 way bound) I would expect the checkbox to always remain in the un-checked state despite the user trying to check it.
This is not the case, however. The user can still check the box and the active state is still false, yet the selected state changes. What is preventing change detection from seeing that the checkbox DOM state is different than the model when that model has changed?
Does the change detection only watch the specific DOM elements and since the active state hasn't changed it assumes the DOM hasn't been affected?
How do I get change detection to see this change and utilize the model value accordingly?