AngularJS controller code:
function AuthConfig($stateProvider, $httpProvider) {
'ngInject';
// Define the routes
$stateProvider
.state('app.login', {
url: '/login',
templateUrl: 'auth/auth.html',
title: 'Sign in'
})
.state('app.register', {
url: '/register',
templateUrl: 'auth/auth.html',
title: 'Sign up'
});
};
export default AuthConfig;
I am not able to figure out what is the use of ngInject. Could someone please help me?
Usually ngInject is needed for the application to work when minified once you deploy in production. If you remove it and use optimize version it should fail.
Read more about
AngularJs Minification and Annotation
'ngInject';
does nothing by itself, it's just a string literal. A tool called ng-annotate uses it as a flag : if a function starts with'ngInject';
, it will be processed by ng-annotate.Basically, ng-annotate will transform
to
in order to make the code minification-safe.
If you're not using ng-annotate, you can safely ignore or remove the expression. Be careful though, you might break the build process of the project if it does use ng-annotate. For more information about ng-annotate and what it does, see https://github.com/olov/ng-annotate