[英]AngularJs - Using ng-options in select
我目前正在嘗試在選擇中顯示存儲在API中的類別列表,但我無法選擇顯示它。
我的類別列表存儲在storageService.poi.categories中(categories是一個內部包含多個對象的數組,這些對象具有'label'作為屬性,而這正是我試圖顯示的內容,例如:storageService.poi.categories [0] .label將顯示'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
如果您在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被顯示在選項文本中。
對於Angular2,它看起來像
<select [ngModel]="newPoi.categorie" name="categorie" class="categorie">
<option *ngFor="let cate in storageService.poi.categories" [ngValue]="cate">{{cate.label}}</option>
</select>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.