0

我试图通过依赖 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']; 
    }
  }
}]);

这个看似直截了当的指令未能呈现正确的下拉选项。为什么?

plunk:http ://plnkr.co/edit/PDmtUn2zBs2329PkHYiF?p=info

4

1 回答 1

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];
}
于 2014-04-04T09:44:05.977 回答