Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
665 views
in Technique[技术] by (71.8m points)

checkbox - Bind angular mat-checbox ngModule

I have an Array of mat-checbkox, where user can only select one option:

export enum ProjectStatus {
  Ready = "Is ready",
  Testing = "is testing",
  Done = "is done"
}

<div *ngFor="let status of projectStatus; let i=index">
    <mat-checkbox [checked]="selected.index === i"
        (change)="selected.index = i; selected.status=status; selected.checked= true;">{{status}}
    </mat-checkbox>
</div>

Then I got some others mat-checkbox:

<div>
    <mat-checkbox>SEND REPORTS</mat-checkbox>
</div>
<div>
    <mat-checkbox>WARN DEVELOPERS</mat-checkbox>
</div>
<div>
    <mat-checkbox>WARN PROJECT MAANGER</mat-checkbox>
</div>
<div>
    <mat-checkbox>WARN TESTERS</mat-checkbox>
</div>

My question is, how I can check another mat-checkbox dynamically based on the first checkbox list checked. I have to use ngModule?

For example, If I select:

is Testing

I want to check automatically the checkboxs:

SEND REPORTS
WARN DEVELOPERS

enter image description here

That's the link of the testing application: https://stackblitz.com/edit/angular-vrnk7t-bxeplb?file=src%2Fapp%2Fcheckbox-overview-example.html

question from:https://stackoverflow.com/questions/65920948/bind-angular-mat-checbox-ngmodule

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try using:

I have made changes in you stackblitz, currently it's works as per your condition.You can use ngModule or some flags to checked the checkbox

https://stackblitz.com/edit/angular-vrnk7t-zrn5x5?file=src%2Fapp%2Fcheckbox-overview-example.ts


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...