[Fixed] Angular/material ui – programatically select mat-selection-list

Issue

I have a mat-selection-list that I need to programmatically check specific items when the component loads. The items I need to check will be selected based on the [value] of the mat-list-option. I can’t find any documentation on this. The html is pretty simple:

<mat-selection-list color="primary" #suretyList formControlName="AgentAgencyAndSureties">
    <mat-list-option *ngFor="let surety of suretyNames" [value]="surety.Id">
        {{surety.SuretyName}}
    </mat-list-option>
</mat-selection-list>

I just want to check items with a specific surety.Id in the value. It doesn’t seem like this should be too hard to do but like I said, I can’t find any examples or good documentation on this.

I am using Angular 10 for both the core and material UI

Solution

try mat-list-option selected input.

<mat-list-option  [selected]="condition">....

Leave a Reply

(*) Required, Your email will not be published