Is the array necessary ?
app.controller('myController', ['$scope', function($scope){
}])
Will this work like the code above?
app.controller('myController', function($scope){
})
The array is always necessary, but it doesn't have to be combined into the controller definition. There is a much cleaner way to do it, and its my preferred method. What I do is create the controller in a functional manner. So for example:
app.controller('myController', MyController);
//dependency injection done here using the array of definitions
MyController.$inject = ['$scope'];
//all of the dependencies are added as parameters into the controller function
function MyController ($scope) {
//insert controller code
}
As pointed out in the answer by Sajeetharan, this is called the explicit method. You should check out this style guide that is endorsed by the Angular 1 team for other patterns that help make the code cleaner and easier to maintain
Yes it will work in the same way, its just the difference.You need to use explicit dependency injection(second way).
Even when you minify it converts $scope to variable a and $http to variable b, their identity is still preserved in the strings.