2
I am using Angular Material in my application, and it in turn has this list created to fill in my input:
lista: any[] = [
{
name: 'Cursos',
tribunais: [
{ value: 'RDC1'},
{ value: 'RDC2'},
{ value: 'RDC3'},
{ value: 'RDC4'},
{ value: 'RDC5'},
{ value: 'INF' }
]
}
]
And I have my HTML component, which renders this list:
<mat-form-field>
<mat-select placeholder="Cursos" multiple>
<mat-optgroup *ngFor="let group of lista" [label]="group.name" [disabled]="group.disabled">
<mat-option *ngFor="let tribunais of group.tribunais" [value]="tribunais.value">
{{tribunais.value}}
</mat-option>
</mat-optgroup>
</mat-select>
</mat-form-field>
However I want to leave some pre-marked inputs when I start my component, as I do to leave marked some options pre-defined?
I tried, it just doesn’t work that way
– Marcelo Henrique Dos Reis
@Marcelohenriquedosreis tries in the new way
– Victor Henrique
also did not give, I think that and because there is one go inside another, and he cannot associate ngModel with the value
– Marcelo Henrique Dos Reis
Put ngModel and selected, then insert the interpolation into html
{{ selecionado | json }}
for you to analyze the contents of the selected ones. So you will know correctly the values of eachselect
.– Victor Henrique
thus: [(ngModel)]="{{ selected | json }}" ? , pq I tried and gave error at angular
– Marcelo Henrique Dos Reis
No. use ngModel as I did in reply. o
{{ selecionado | json }}
you will add in your HTML code just like you did with thetribunais.value
. but you’ll put him on top of themat-form-field
– Victor Henrique
I did not understand the explanation, can make an update in the code to understand better?
– Marcelo Henrique Dos Reis
Let’s go continue this discussion in chat.
– Victor Henrique