我试图通过依靠ng-options来构建一个非常简单的选择。
angular.module('foo', []).directive('listSelect', ['$injector', function(injector){
return {
restrict: 'E',
template: "<select ng-options='val as val for val in list'></select>",
link: function(scope, elem, attrs){
scope.list = ['foo', 'bar', 'bazz'];
}
}
}]);
看似直截了当的指令未能提供正确的下拉选项。为什么呢?
答案 0 :(得分:3)
您的选择缺少模型。
template: "<select ng-model='hier' ng-options='val for val in list'></select>"
link: function (scope) {
scope.list = ['foo', 'bar', 'bazz'];
scope.hier = scope.list[0];
}