0

我希望能够访问 ng-repeat 内的 ng-options 中的一组选择选项,但是 ng-repeat 创建了一个新范围,我无法再访问它。有没有办法解决这个问题而不将其添加到重复数据中?

<body ng-controller="mainCtrl" class="container">
    <test repeater="repeater"></test>
</body>

模板:

<div ng-repeat="repeat in repeater">
    <span>{{repeat.type}}</span>
    <select ng-options="value for value in options">
         <option value="">Choose one:</option>
    </select>
</div>

JS:

angular.module('app').controller('mainCtrl', function($scope) {
  $scope.repeater = [
    {
      type: 'best'
    },
    {
      type: 'worst'
    },
    {
      type: 'ok'
    }
  ];
});

angular.module('app').directive('test', function() {
  return {
    scope: {
      repeater: '='
    },
    templateUrl: 'test.html',
    controller: function($scope) {
      $scope.options = ['Nope', 'Yup', 'Sure'];
    }
  };
});

普朗克

4

1 回答 1

3

你很接近,但缺少一件事。ng-model

<select ng-model="selectedOption" ng-options="value for value in options">
     <option value="">Choose one:</option>
</select>
于 2015-03-12T22:40:32.833 回答