<select
get-sport
name="sportId"
id="sportId"
ng-model="sm.sport_id"
ng-change="changeSport()"
ng-options="sport.sport_id as sport.name for sport in sports track by sport.sport_id"
ng-required="true">
<option value="" selected="selected">-- Select Sport--</option>
</select>
return {
scope : true,
link : function (scope) {
scope.spinning = true;
$http.get('v1/sport')
.success(success)
.error(error);
function success(data){
scope.sports = data.data;
scope.spinning = false;
}
function error(error) {
console.log(error);
}
}
};
在我的控制檯Array [ Object, Object, Object, Object, Object, Object, Object, Object, Object ]
獲得在NG選項空白值angularjs
目標對象的名稱:板球,sport_id: '1'
進入我的sm.sport_id獲得價值3應該等於名稱:足球,sport_id:3,但默認情況下它是選擇空值我不明白爲什麼請指導感謝一噸提前
請添加一個json數組示例 –
對象{sport_id:「1」,name:「Cricket」} Object {sport_id:「2」,name:「Hockey」} Object {sport_id:「1」,名稱:「足球」} – Amy
請參閱此博客https://www.undefinednull.com/2014/08/11/a-brief-walk-through-of-the-ng-options-in-angularjs/ – Winnie