我有以下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' }
];
}]);
然后来自here的tabset
指令也引入了自己的控制器TabsetController
,它还定义了范围上的tabs
属性:
.controller('TabsetController', ['$scope', function TabsetCtrl($scope) {
var ctrl = this,
tabs = ctrl.tabs = $scope.tabs = [];
该元素将使用哪个控制器的tabs
属性?
有关完整示例,请参阅this Plunker。