Angular JS controller

76 Views Asked by At

I am a little confused in the syntax for the controller in angular js: Both the following controller work when I use {{ and }}.

Could someone tell me what is use of the parameters $scope and $filter before the function($scope..), the one in bold. Also when I remove one of these, I dont get the output. 'MyController1', ['$scope', '$filter',function($scope

    app.controller('MyController1', ['$scope', '$filter',function($scope,    $filter) {
$scope.an = $filter('uppercase') ("ankurbhatia");

}]);

Here I have removed the $scope and $filter before the function but it still works.

app.controller('DemoController',
function($scope, $filter) {
$scope.an= $filter('uppercase')('Ari');
});
1

There are 1 best solutions below

3
On BEST ANSWER

It is usefull if you minify your JavaScript. If you state the "stringified" variable before, the minified JS will still find what the minifed variable should be.

Your JavaScript minifed will be

app.controller("MyController1",["$scope","$filter",function(r,a){r.an=a("uppercase")("ankurbhatia")}]);

If you dont specify the string before, it will look like this:

app.controller("MyController1",function(o,r){o.an=r("uppercase")("ankurbhatia")});

Se the section "A Note on Minification" at https://docs.angularjs.org/tutorial/step_05