I want to have in all my select boxes the value of "Select an option"
I have fixed it for the first one like this:
<select class="form-control" [(ngModel)]="selectedPrototypeSelector" (ngModelChange)="onPrototypeChange()">
<option *ngFor="#p of prototypes" [value]="p.selector">
{{ p.selectorName }}
</option>
</select>
and in the component:
private selectedPrototypeSelector: string = "Select an option";
And I created a fake object in my expression.array.ts
like this:
{
selector: "Select an option",
selectorName: "Select an option",
constraints: "Select an option"
},
But I would like to set it for all the select boxes and here is the template for the second second select box:
<select class="form-control" [(ngModel)]="expression.constraint">
<option *ngFor="#constraint of prototype.constraints" [value]="constraint">
{{ constraint }}
</option>
</select>
Where I bind it to the object expression, how can I fix this?
This is what i want to achieve I did this in photoshop:
Here is a Plunker to get a better overview.
2
Answers
You could set the expected value in the
constraint
property of theexpression
object:Edit
Since the
selectedPrototypeSelector
property of the expression component is used to select the value, you need define it as an inputand provide the expected value when using the component:
See this plunkr: https://plnkr.co/edit/LjfiY4?p=preview.
Add an initial value for
selectedPrototypeSelector
on your component.For example you could have:
and then:
where:
So, on your template in order to have the first element of barList as initial value for the select box you must: