这是我的angularjs指令:
dicApp.directive('listpanel', function ($resource) {
return {
restrict: 'E',
template: '<select ng-model="selectedDictionary" ng-change="listChange()">' +
'<option value="">--Select--</option>' +
'<option ng-repeat="item in items" value="{{item.value}}">{{item.label}}</option> ' +
'</select>',
replace: true,
link: function (scope, elem, attrs) {
var list = $resource('http://test.com')
list.get(function (data) {
scope.items = [];
for(var index = 0; data.documents[0].Dictionaries.length > index; index++){
scope.items.push({'label': data.documents[0].Dictionaries[index].Label.text, 'value': data.documents[0].Dictionaries[index].Glossaries._id});
}
scope.selectedDictionary = '51639519ed7f3dd05869c3d9';
console.log(data.documents[0].Dictionaries[0].Glossaries._id);
//scope.selectedDictionary = data.documents[0].Dictionaries[0].Glossaries._id;
});
}
}
});
我很确定绑定的scope.items中存在值51639519ed7f3dd05869c3d9
,但select
中从未选择selectedDictionary。我错过了什么?
答案 0 :(得分:1)
尝试以这种方式创建选项<select ng-model='data' ng-options="item for item in list"> </select>