3

I wrote a really simple angular module that allows a tabbed-navigation (the code is simplified, but does not work either):

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;
});

and I include the module in another one:

var directives=angular.module("directives",["tabsModule"]);

But when I use it, I got this error:

Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- tabsDirective

I have no idea where it comes from, I've made dozens of modules/directive, and I think I've made this one like I always do...

I'm stuck on it for hours, please help !!!!

Edit: I didn't specify it but I was using requirejs, and it was the cause of this issue.

6
  • can you provide plunk link >>? Commented Jun 26, 2015 at 14:26
  • It's working for me plnkr.co/edit/MWyO99jZeryqmH7viTwO?p=preview Commented Jun 26, 2015 at 14:28
  • damn! I'm gonna investigate a bit more and edit my question... Commented Jun 26, 2015 at 14:34
  • tabsDirective isn't taking any dependency on $scope, nor should it... From the angular docs, do this: link: { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function postLink(scope, Element, iAttrs, controller) { ... } } Commented Jun 26, 2015 at 15:11
  • I don't understand what you mean... Commented Jun 28, 2015 at 12:30

2 Answers 2

1

The error is that you are not passing the tabs function to the directive method of angular. See the mismatch of the parameters:

define(["angular","./controller","./tabs","./pane"],function(tabsController,tabs,pane){

Instead do:

define(["angular","./controller","./tabs","./pane"],function(angular, tabsController, tabs, pane){
Sign up to request clarification or add additional context in comments.

2 Comments

It looks like we unswared at the same time
yeah, but I'll give you all the glory :-)
0

Finally, I just got it, I forgot to add angular as parameter in module.js, so every argument was in the wrong place.

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;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.