如果应用于一个html元素的两个控制器在范围上定义它,那么scope属性会发生什么

时间:2014-07-14 09:29:50

标签: angularjs angular-bootstrap

我有以下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' }
  ];
}]);

然后来自heretabset指令也引入了自己的控制器TabsetController,它还定义了范围上的tabs属性:

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

该元素将使用哪个控制器的tabs属性? 有关完整示例,请参阅this Plunker

0 个答案:

没有答案