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?
'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.
The $watch keep an eye on the variable and as the value of the variable changes the angular JS $what runs a function. This function takes two arguments one is the new value and another parameter is the old value.
Dependency Injection in AngularJS can be defines as the software design pattern which defines the way the software components are dependent on each other. AngularJS provides a set of components that can be injected in the form of dependencies such as factory, value, constant, service, and provider.
Answer: D is the correct answer. 30) Which of the following statement is true in the case of $routeProvider? It is a service.
'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
angular.module("MyMod").controller("MyCtrl", function($scope, $timeout) { "ngInject"; ... });
to
angular.module("MyMod").controller("MyCtrl", ["$scope", "$timeout", function($scope, $timeout) { "ngInject"; ... }]);
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With