简体   繁体   中英

I have a array of objects to check from that primary is true is only one time on the checkbox otherwise show alert

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM