0

我有以下 HTML:

<div ng-controller="MainController">
    <div class="words">
      <span ng-repeat="word in words" ng-click="setActiveWord(word)"> {{word.name}}</span>
    </div>

    <tabset>
      <tab ng-repeat="tab in tabs" heading="{{tab.title}}" active="tab.active" disabled="tab.disabled">
        {{activeWord.name}}
      </tab>
    </tabset>
</div>

然后我有一个定义,MainController它将tabs属性添加到范围:

.controller('MainController', ['$scope', function($scope) {
  $scope.setActiveWord = function(word) {
    $scope.tabs[0].active = true;
  }

  $scope.tabs = [
    { title:'Dynamic Title 1', content:'Dynamic content 1' },
    { title:'Dynamic Title 2', content:'Dynamic content 2' }
  ];
}]);

然后来自这里tabset的指令还引入了它自己的控制器,它也定义了范围上的属性:TabsetControllertabs

.controller('TabsetController', ['$scope', function TabsetCtrl($scope) {
  var ctrl = this,
      tabs = ctrl.tabs = $scope.tabs = [];

哪个控制器的tabs属性将用于元素?请参阅此 Plunker以获取完整示例。

4

0 回答 0