我写了一个非常简单的角度模块,允许选项卡式导航(代码简化,但也不起作用):
module.js
define(["angular","./controller","./tabs","./pane"],function(tabsController,tabs,pane){
var module = angular.module("tabsModule",[])
.controller("tabsController",["$scope",tabsController])
.directive("tabs",tabs)
//.directive("pane",pane);
return module;
});
tabs.js
define([], function() {
function tabs() {
var directive = {
restrict: "E",
controller: "tabsController",
scope: true,
templateUrl: "html/directives/tabs.html",
link: {
pre: function(scope, element, attrs, controller) {
scope.addPane = controller.addPane.bind(controller);
scope.select = controller.select.bind(controller);
}
},
// transclude: true,
};
return directive;
}
return tabs;
});
controller.js
define(["controllers/prototypes/base_controller"],function(BaseController){
var TabController=BaseController.extend({
constructor:function($scope){
BaseController.call(this,$scope);
this.$scope.panes = [];
this.directivesEvents=directivesEvents;
},
addPane:function(pane) {
if (pane.order === 0) {
this.$scope.select(pane);
}
this.$scope.panes = this.$scope.panes.concat(pane).sort(function(a, b) {
return a.order - b.order;
});
},
select:function(pane) {
angular.forEach(this.$scope.panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
this.$scope.$emit(this.directivesEvents.TAB_CHANGE, pane.id);
}
});
var TabController=function($scope){
};
TabController.$inject=["$scope"];
return TabController;
});
我将模块包含在另一个模块中:
var directives=angular.module("directives",["tabsModule"]);
但是当我使用它时,我收到了这个错误:
错误:[$ injector:unpr]未知提供者:$ scopeProvider< - $ scope< - tabsDirective
我不知道它来自何处,我已经制作了数十个模块/指令,而且我认为我已经像往常那样制作了这个模块/指示...
我坚持了几个小时,请帮忙 !!!!
修改:我没有指定它,但我使用的是requirejs,这就是导致此问题的原因。
答案 0 :(得分:1)
错误是您没有将tabs函数传递给angular的指令方法。请参阅参数不匹配:
define(["angular","./controller","./tabs","./pane"],function(tabsController,tabs,pane){
取而代之的是:
define(["angular","./controller","./tabs","./pane"],function(angular, tabsController, tabs, pane){
答案 1 :(得分:0)
最后,我刚刚得到它,我忘了在angular
中添加module.js
作为参数,所以每个参数都在错误的位置。
define(["angular","./controller","./tabs","./pane"],function(angular,tabsController,tabs,pane){
var module = angular.module("tabsModule",[])
.controller("tabsController",["$scope",tabsController])
.directive("tabs",tabs)
//.directive("pane",pane);
return module;
});