I have a array of objects to check from that primary is true is only one time on the checkbox otherwise show alert see image below:-
<mat-checkbox class="example-margin" [(ngModel)]="primary" formControlName="primary"> Make this primary </mat-checkbox>
In this array of object there are 2 primary = true in that
Suppose your array is data
.
let primaryGuys = data.filter(person => person.primary === true);
if(primaryGuys >1) {
alert('HEY!')
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.