下面这段代码有注释的地方是我不懂的地方,还请大神帮我解释下,这个是个tab切换的效果,如果愿意的话还请帮忙解释下这里面的逻辑,万分感谢!!!
directive('tabs', function() {
return {
restrict: 'E',
transclude: true,
scope: {},
controller: ["$scope", function($scope) {//为什么是数组呢:"$scope"该怎么理解呢
var panes = $scope.panes = [];
$scope.select = function(pane) {
angular.forEach(panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
}
this.addPane = function(pane) {//这里的this该怎么解释,为什么能直接this.addPane呢
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-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的问题太多了,你需要好好看一下Angular的模型、作用域(scope)、数据绑定。
讲道理学习JS框架从Demo学起并不是一个很好的方式,应该先了解一下框架的原理(DOM渲染、数据绑定、事件传递)。
`return {