I am trying to create a wrapper component for inputs such as a checkbox but I cannot get the parent (inputValue) variable to change, even though it is set as an ngModel.
This is my component definition:
@Component({
selector: 'my-checkbox',
inputs: ['inputValue', 'label'],
template: `
<div class="ui checkbox">
<input type="checkbox" name="example" [(ngModel)]="inputValue" (change)="onChange($event)">
<label>{{label}}</label>
</div>`
})
export class CheckboxComponent {
inputValue: boolean;
onChange(event) {
this.inputValue = event.currentTarget.checked;
console.log(this.inputValue);
}}
And I am using it like this in the parent view:
<my-checkbox [inputValue]="valueToUpdate" [label]="'Test Label'"></my-checkbox>
The console does log correctly and I can see that the internal (inputValue) is updating but not the external 'valueToUpdate' (the ngModel two-way binding is not updating correctly).