The difference between the two is that the notation []
bracket minifier -safe as minifiers does not minimize lines. For example, if you try to minimize javascript without it, it will turn:
angular.module('myApp', []) .controller('MainController', function($scope) { });
in
angular.module("myApp",[]).controller("MainController",function(e){})
The problem in this case is that Angular knows nothing about e
, not about the $scope
that it knows about. Using the []
notation, we can tell $injector
in advance that we want the controller to gain access. Since minifiers do not (and cannot) minimize strings, this is a safe way to use the Angular injection function with or without minifiers.
For a deeper understanding of syntax differences, you can check out ng-book ( https://www.ng-book.com/ ). Disclaimer, I am the author of the book and http://www.ng-newsletter.com/ .
auser source share