When I select one checkbox, the others should be automatically unselected. Additionally, clicking on a selected checkbox should also deselect it. Currently, my implementation looks like this:
In the HTML page, I am utilizing *ngFor in the following manner:
<ng-container *ngFor="let item of items">
<div>
<p-checkbox (onChange)="changeValue(item.value)" [(ngModel)]="selectedValue" name="test" value="{{item.value}}" [inputId]="item.value"></p-checkbox>
<label [for]="item.value">{{item.label}}</label>
</div>
</ng-container>
Within my component, I have the following setup:
public items: any[] = [
{ label: 'labelOne', value: true },
{ label: 'labelTwo', value: false }
]
public selectedValue;
public changeValue(value) {
this.selectedValue = value;
}
Everything is functioning as expected, but an error pops up in the console upon clicking on a selected checkbox:
Checkbox.html:7 ERROR TypeError: this.model.filter is not a function
at Checkbox.push../node_modules/primeng/fesm5/primeng-checkbox.js.Checkbox.removeValue (primeng-checkbox.js:87)
at Checkbox.push../node_modules/primeng/fesm5/primeng-checkbox.js.Checkbox.updateModel (primeng-checkbox.js:62)
at Checkbox.push../node_modules/primeng/fesm5/primeng-checkbox.js.Checkbox.onClick (primeng-checkbox.js:52)
at Object.eval [as handleEvent] (Checkbox.html:7)
at handleEvent (core.js:29239)
at callWithDebugContext (core.js:30309)
at Object.debugHandleEvent [as handleEvent] (core.js:30036)
at dispatchEvent (core.js:19859)
at core.js:28448
at HTMLDivElement.<anonymous> (platform-browser.js:1032)
Any insights into what might be going wrong? Thank you!