5

如果它是一个文本框而不是一个选择,这不会像它那样显示选定的值。怎么了?

<md-select #mySelect>
    <md-option value="1">one</md-option>
    <md-option value="2">two</md-option>
</md-select>
{{ mySelect.value }}
4

2 回答 2

6

试试#variable.selected.value这样:

<md-select #mySelect>
    <md-option value="1">one</md-option>
    <md-option value="2">two</md-option>
</md-select>
<div *ngIf="mySelect.selected">
    {{mySelect.selected.value}}
</div>
于 2017-01-26T01:34:27.217 回答
0
<form>
    <md-select placeholder="Favorite food" [(ngModel)]="selectedValue" name="food">
    <md-option *ngFor="let food of foods" [value]="food.value">
    {{food.viewValue}}
    </md-option>
    </md-select>enter code here
    <p> Selected value: {{selectedValue}} </p>
</form>

你能试试这个吗?

于 2017-01-30T11:44:27.920 回答