1

I want select a option in my select - option in my html with Angular2 , but I need do this for code.

<select name="lastDataVi" [(ngModel)]="lastDataVi">
   <option [ngValue]="undefined" selected="true" disabled="disabled">Select option</option>
   <option [ngValue]="vicombo.id" *ngFor="let vicombo of paramsServer.vicombo"> {{ vicombo.id}} </option>
   </select>

although I have my
<option [ngValue]="undefined" selected="true" disabled="disabled">Select option</option>

I need when I do click the button , Put the select- option in the frist option ->

<option [ngValue]="undefined" selected="true" disabled="disabled">Select option</option>

3
  • You just need to assign the selected value to this lastDataVi Commented Sep 24, 2018 at 8:39
  • but in my html I want that my user see the first option , not that I have the value = undefined" Commented Sep 24, 2018 at 8:42
  • still your expected is output is not clear. Commented Sep 24, 2018 at 8:44

2 Answers 2

1

You need to use [value] instead of [ngValue]

 <option  *ngFor="let vicombo of paramsServer.vicombo" [value]="vicombo.id"> {{ vicombo.id}} </option>
Sign up to request clarification or add additional context in comments.

Comments

0

You could use

<option selected="true" disabled="true"></option>

You need not use ngValue.

3 Comments

nop. without ngValue. In html never shows 1º option
Also you could refer this stackoverflow.com/questions/5805059/…
Created a plunker. See if it helps next.plnkr.co/edit/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.