Html Angular 5 下拉菜单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49031113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 15:09:10  来源:igfitidea点击:

Angular 5 dropdown menu

htmlangulartypescript

提问by Mr. Toast

Angular 5 I cant get the dropdown menu to display the "category", the category exsist in item.category and categories, and is the same. I've tried with ngModel and ngValue and just value and cant get it to work

Angular 5 我无法让下拉菜单显示“类别”,该类别存在于 item.category 和类别中,并且是相同的。我已经尝试过 ngModel 和 ngValue 并且只是价值并且无法让它工作

<td>
   <select [(ngModel)]="item.category">
        <option style="display:none">select a category</option>
        <option *ngFor="let item of categories" [ngValue]="item.category" value="item.category">{{item.category}}</option>
      </select>
    </td>

回答by Lonna

For me work like this:

对我来说,像这样工作:

<select [(ngModel)]="category" id="category">
   <option value="" disabled selected>select a category</option>
   <option *ngFor="let item of categories" [value]="item.category">{{item.category}}</option>
 </select>