Skip to content

Instantly share code, notes, and snippets.

@krshubham
Created September 11, 2016 10:40
Show Gist options
  • Save krshubham/eb1dee793e261cd43eef43beb288fe50 to your computer and use it in GitHub Desktop.
Save krshubham/eb1dee793e261cd43eef43beb288fe50 to your computer and use it in GitHub Desktop.
A solution to common Angular error [$injector:modulerr]
Recently I was also stuck with this error and was very much disturbed because of this.
Some steps which according to me , you should not forget when including a service in your angular app:
The first part is to use angular.js unminified file which gives you readable errors which you can at least read and try to figure out
what's happening.In my case, I forgot to mention my service in index.html which gave me this error.
1) Add the exact name of the module(factory, service or provider) in the core module of the app. For example:
var app = angular.module('codeslam', [
'authservice',
'codeservice',
'controllers',
'routes'
]);
I have to list all my dependencies in the core module correctly spelt.
2) Include the name of the factory or service or provider in the controller wihtout any spelling mistakes in both the versions:
string and the variable.
For example:
app.controller('codeController',['Code' ,function(Code){
//do something here
}
3) Lastly the most important do not forget to include the service or dependencies file in your core index.html view(whatever the name is).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment