I am new to AngularJS. What is difference between a controller declared with an array parameter, listing the dependencies both as strings and as JavaScript names,
app.controller("firstController", ['$scope', '$modal', '$log', 'HttpService', 'FisrtSharedService', 'SecondSharedService', function($scope, $modal, $log, HttpService, FisrtSharedService, SecondSharedService) {
}]);
...and this form, listing just the JavaScript names?
app.controller("firstController", function($scope, $modal, $log, HttpService, FisrtSharedService, SecondSharedService){
});
Why the weird syntax in the first version?
In AngularJS, $scope is the application object (the owner of application variables and functions). The controller creates two properties (variables) in the scope (firstName and lastName). The ng-model directives bind the input fields to the controller properties (firstName and lastName).
In AngularJS, a Controller is defined by a JavaScript constructor function that is used to augment the AngularJS Scope. Controllers can be attached to the DOM in different ways.
All the AngularJS application mainly relies on the controllers to control the flow of data in that application. Basically, it controls the data of AngularJS applications and the controller is a Javascript object, created by a standard JavaScript object constructor.
A controller is a function you write to control your data. With a self-written controller, you can modify data anyway you want: Convert to upper case. Convert currencies. Calculate and Summarize.
It's used when you minified JS files. '$scope', '$modal', '$log', 'HttpService', 'FisrtSharedService', 'SecondSharedService'
just declares injectors.
app.controller("firstController", ['$scope', '$modal', '$log', 'HttpService', 'FisrtSharedService', 'SecondSharedService', function($scope, $modal, $log, HttpService, FisrtSharedService, SecondSharedService) {
}]);
You also declare injectors like this:
firstController.$inject = ['$scope', '$modal', '$log', 'HttpService', 'FisrtSharedService', 'SecondSharedService'];
app.controller("firstController", function($scope, $modal, $log, HttpService, FisrtSharedService, SecondSharedService){
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With