尝试使用自定义指令时,我一直收到行包参数错误。
我的HTML:
<product-panels ng-controller="PanelController as panels"></product-panels>
我的指示:
app.directive('productPanels', function(){
return{
restrict: 'E',
templateUrl: 'product-panels.html',
controller: function(){
this.tab = 1;
this.selectTab = function(setTab){
this.tab = setTab;
};
this.isSelected = function(checkTab){
return this.tab === checkTab;
};
},
controllerAs: 'panels'
};
});
我继续被告知PanelController不是一个函数,并且已经变得未定义。我不是为什么,除非我错过了在某个地方命名。谢谢你的帮助。
答案 0 :(得分:0)
由于该指令拥有控制器,因此您不需要在对该指令的html调用中声明它。您只需使用panels.<whatever property/function you need>
。
答案 1 :(得分:0)
You have already included the path of HTML. So you dont need to add ng-controller
in your HTML.
Html Should be simpler as:-
<product-panels>
// Add HTML code here for which you want to use this directive
</product-panels>