directive('tabs', function() {
return {
restrict: 'E',
transclude: true,
scope: {},
controller: ["$scope", function($scope) {
var panes = $scope.panes = [];
$scope.select = function(pane) {
angular.forEach(panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
}
this.addPane = function(pane) {
if(panes.length == 0) $scope.select(pane);
panes.push(pane);
}
}],
template: '' + '
' + '' + '',
replace: true
};
}).
directive('pane', function() { return { require: '^tabs',//
restrict: 'E',
transclude: true,
scope: {
title: '@'
},
link: function(scope, element, attrs, tabsCtrl) {
tabsCtrl.addPane(scope);//这里为什么传scope参数呢
},
template: '' +//ng-class="{active: selected}"怎么理解呢
'
',
replace: true
};
})
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
controller里边有select和addPane所有用数组,
ng-repeat="pane in panes" 是一个循环吧所有传入的是pane
ng-class="{active: selected}" 当被选择的时候激活class
个人理解,仅供参考
还是angular2好理解