这是我的天使指令:
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;
});
}
}
});我确信51639519ed7f3dd05869c3d9值存在于绑定的scope.items中,但是selectedDictionary从未在select中被选中。我遗漏了什么?
发布于 2013-11-13 06:33:32
尝试以这种方式创建选项<select ng-model='data' ng-options="item for item in list"> </select>
https://stackoverflow.com/questions/19946441
复制相似问题