selected does not work in multiple select in angular 4

1

the selected property does not work on angular 4. for example if I cycle

<select multiple >
<option *ngFor="let opt of model" selected>
   opt.name
</option>

and there is 10 option only going to select the last element. This happens to me in any project that makes angular. Any for that I put, and if I put selected not select all as I should

    
asked by santiago 23.03.2018 в 03:35
source

1 answer

0

You can use the following:

<select multiple >
<option *ngFor="let opt of model" [attr.selected]="true">
   opt.name
</option>

Although the ideal would be to use a form, associate the select with a value (an array) that you have in your controller and let Angular select the matching options.

    
answered by 24.03.2018 / 22:57
source