Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>All of them are valid, but exposing global functions is usually not a good idea (names can clash), sot it is better to have the functions encapsulated in angular's own domain.</p> <p>This makes style #2.</p> <p>AngularJS uses <code>dependency injection</code> to provide other services, filters, controllers etc. This is done by peeking the function parameters, getting them via regex and providing them as necessary.</p> <p>But, what happens when you minify? To get rid of extra bytes, the minifiers rename the variables and parameters within the function, since it not change anything and everything would work if we were not peeking to get the parameters of the function.</p> <p>When minified, e.g. <code>$rootScope</code> becomes <code>a</code>, and it will throw an error like there is no <code>aProvider</code>, yeah that's right.</p> <p>So, angular has another syntax, it is the array notation; instead of defining a function, you can define an array which has the dependency names followed by the implementing function.</p> <p>So,</p> <pre><code>angular.controller("MainCtrl", ["$scope", "$routeParams", function (a,b) { // a == $scope // b == $routeParams }]); </code></pre> <p>There are also other ways to do it, instead of defining an array. You can set the function's $inject property to an array.</p> <pre><code>function MainCtrl(a,b) { // a == $scope // b == $routeParams } MainCtrl.$inject = ["$scope", "$routeParams"]; </code></pre> <p>For further info: <a href="http://docs.angularjs.org/guide/di" rel="nofollow">http://docs.angularjs.org/guide/di</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload