Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found in angularjs

I want to wrap this https://gist.github.com/nblumoe/3052052 in a module. I just changed the code from TokenHandler to UserHandler, because on every api request I want to send the user ID.

However I get module UserHandler not found in firebug console. Here is my full code: http://dpaste.com/1076408/

The relevent part:

angular.module('UserHandler').factory('UserHandler', function() {
    var userHandler = {};
    var user = 0;

    /...

    return userHandler;
});

angular.module('TicketService', ['ngResource', 'UserHandler'])
       .factory('Ticket', ['$resource', 'UserHandler',
                function($resource, userHandler){

    var Ticket = $resource('/api/tickets/:id1/:action/:id2',
    {
        id1:'@id'
    }, 

    { 
        list: {
            method: 'GET'
        }
    }); 

    Ticket = userHandler.wrapActions( Ticket, ["open", "close"] );

    return Ticket;
}]); 

Any idea why this happens? How to fix it?

like image 393
UpCat Avatar asked Apr 28 '13 07:04

UpCat


People also ask

Can not find module in Angular?

To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the baseUrl option to src in your tsconfig. json file and restart your IDE and development server. Copied!

Where is module in Angular?

Every Angular application has at least one NgModule class, the root module, which is conventionally named AppModule and resides in a file named app. module. ts .

How many $rootScope an AngularJS application can have?

An app can have only one $rootScope which will be shared among all the components of an app. Hence it acts like a global variable. All other $scopes are children of the $rootScope.

Which of the following components can be injected as a dependency in AngularJS?

Which of the following components is the one which can be injected as a dependency in Angular JS? Answer: C) Application module can be injected as a dependency in AngularJS.


1 Answers

Many has fallen into the same trap. Me included.

The following does not define a new module. It will try to retrieve a module named UserHandler which isn't defined yet.

angular.module('UserHandler')

Providing a (empty) array of dependencies as the second argument will define your module.

angular.module('UserHandler', [])
like image 138
Bart Avatar answered Oct 14 '22 11:10

Bart