我目前正在尝试在选择中显示存储在API中的类别列表,但我无法选择显示它。
我的类别列表存储在storageService.poi.categories中(类别是一个包含多个对象的数组,其中'label'作为属性,这就是我想要显示的内容,例如:storageService.poi.categories [0]。标签将显示“TreeStart”)
我现在一直在寻找几个小时,这应该有用(我想?),但它不是
<select ngModel="newPoi.categorie" name="categorie" class="categorie" ng-options="
cate.label for cate in storageService.poi.categories"></select>
感谢您的帮助
编辑:存储的数据:
Object /*<-- This is storageService.poi.categories*/
0:PoiCategory /* This is what the objects inside categories looks like*/
categories:Array[10]
label:"TreeStart"
landmarks:Array[0]
popup:undefined
symbol:undefined
timestamp:undefined
uid:0
uid_parent:undefined
__proto__:Object
67:PoiCategory
70:PoiCategory
71:PoiCategory
72:PoiCategory
73:PoiCategory
74:PoiCategory
答案 0 :(得分:0)
如果您在Angularjs中执行此操作,则ngModel
应为ng-model
然后你可以这样做
<select ng-model="newPoi.categorie" name="categorie" class="categorie" ng-options="
cate as cate.label for cate in storageService.poi.categories">
cate绑定到ng-model,cate.label显示在选项文本中。
答案 1 :(得分:0)
对于Angular2,它看起来像
<select [ngModel]="newPoi.categorie" name="categorie" class="categorie">
<option *ngFor="let cate in storageService.poi.categories" [ngValue]="cate">{{cate.label}}</option>
</select>