i have seen few approach to declare controller in angular.
QS 1
angular.module('MyApp', []);
function MyCtrl($scope) {
angular.element(document).ready(function () {
document.getElementById('msg').innerHTML = 'Hello';
});
}
in the above code no where it is specified that MyCtrl is a part of module name MyApp. do we need to add controller to MyApp module ? or it will be added automatically to MyApp module ?
QS 2
var app;
(function () {
app = angular.module("TestApp", []);
})();
app.controller('TestController', ["$scope", function ($scope) {
$scope.TestAngularMethod = function () {
alert('Hello you are calling angular js method.');
}
}]);
i have seen some people use [] to inject dependency like ["$scope" but some people do not use 3rd bracket to inject dependency.
see this ["$scope" does it carry any special meaning ?
because in function we always specify dependency name like this way function ($scope)
so tell me when 3rd bracket we need to use to inject dependency?
or is it any syntactic sugar or personal preference ?
code taken from http://dotnet-concept.com/Tips/2015/6/5798829/How-to-call-angularJS-function-from-javascript-jquery
learning angular. so encounter various different code and that is why trying to understand. help would be appreciated. thanks
EDIT
i saw this post on the same topic https://stackoverflow.com/a/17954031/508127
they are saying if we declare controller like below one and if we minify then problem may occur but do not discuss why problem will occur.
function MyCtrl($scope) {
angular.element(document).ready(function () {
document.getElementById('msg').innerHTML = 'Hello';
});
}
anyone can shade some light on it. thanks