选择选项不适用于Angular 4中的ng-model [英] select option not working with ng-model in angular 4
本文介绍了选择选项不适用于Angular 4中的ng-model的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个选择框,在其中显示列表中的元素 代码段:
I have a select box where I show elements from a list Code Snippet:
export class CreateauctionComponent implements OnInit{
createAuctionForm: FormGroup;
test:any = ["cat","dog"];
constructor(private _formBuilder: FormBuilder,private _categories: UserCategoriesForAuctionService){
//
}
}
以HTML呈现为:
<div class="form-col">
<h5><span style="color:red;">*</span>{{'createAuction.category' | translate}}:</h5>
<select class="form_cbx long-select" name="" ng-model="test">
<option ng-options="t in test">{{t}}</option>
</select>
</div>
我看不到任何值.列表中只有一个空白字段.任何人都可以在这里解决问题吗?
I am not able to see any values. Only one blank field in the list. Can anyone direct what is the issue here?
推荐答案
应该是
<select [(ngModel)]="selectedanimal" (ngModelChange)="onChange($event)">
<option *ngFor="let c of test" [ngValue]="c"> {{c}} </option>
</select>
这篇关于选择选项不适用于Angular 4中的ng-model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文