Dependency injection issue when minify the js (Mini-challenge 4) Answer

Check out Mini-challenge 4 Instructions

Answer:dependency injection minify challenge

The parameters to the component (e.g. controller, factory, etc)  for dependency injection, will be converted to mangled variables. For example, $scope and $timeout may become a or b and not be found by Angular in the code inside the controller, factory, etc.

For example this:

(...)
myApp.controller('MyCtrl', function ($scope, $timeout) {
(...)
}
});

Could be converted in something like this.

(...)
myApp.controller('MyCtrl', function (a, b) {
(...)
}
});

If you don’t use the $inject service and pass the array of dependencies, you could have errors in your application (see possible solution below).

Solution before minification:

Solution after minification:

You can visit John Papa’s angular-styleguide for more information:

https://github.com/johnpapa/angular-styleguide#manual-annotating-for-dependency-injection

This is Todd Motto recommendation for dependency injection annotation:

http://toddmotto.com/angular-js-dependency-injection-annotation-process/ 

If you have a solution for this challenge, different from the proposal solution on this post, don’t be shy and share it with us. 🙂