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');
});
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
If you dont specify the string before, it will look like this:
Se the section "A Note on Minification" at https://docs.angularjs.org/tutorial/step_05