var app = angular.module('app',['ngPlugin']);
app.controller('frontTourism',['$scope','$http','stModal','$timeout','ngSubmit','alert',function(){/*省略*/}])
The meaning of dependency injection, let me explain it in detail.
An object usually has three ways to gain control over its dependencies: (1) Create dependencies internally; (2) Reference through global variables; (3) Pass parameters where needed. Angular’s dependency injection is implemented through the third way. The remaining two methods will bring various problems, such as polluting the global scope and making isolation extremely difficult. From a functional point of view, dependency injection will automatically find dependencies in advance and inform the injection target of the dependent resources, so that the resources can be injected immediately when the target needs it.
Angular has 3 injection methods: a, inferred injection app.controller('MyCtrl', function($scope) { });
The first method is based on the written parameter name, such as $scope, and calls $inject internally to inject $scope into the dependency. If a compression tool is used in front-end development, $scope will be changed into another letter, and it will not be possible. Inference has been made, and for the other two methods, you can change function($scope) to function(a). It doesn’t matter; The second method requires writing one more line of code; It is generally recommended to use the third method.
These are objects used for injection. Only by injecting these objects can they be used in the following functions $scope is required for page value transfer $http is required for http requests
The meaning of dependency injection, let me explain it in detail.
Angular has 3 injection methods:
a, inferred injection
app.controller('MyCtrl', function($scope) {
});
b, annotated injection
var myFunc=function($scope) {
});
myFunc.$inject = ['$scope'];
app.controller('MyCtrl',myFunc);
c, inline injection
app.controller('MyCtrl', ['$scope', function($scope) {
}]);
The first method is based on the written parameter name, such as $scope, and calls $inject internally to inject $scope into the dependency. If a compression tool is used in front-end development, $scope will be changed into another letter, and it will not be possible. Inference has been made, and for the other two methods, you can change function($scope) to function(a). It doesn’t matter;
The second method requires writing one more line of code;
It is generally recommended to use the third method.
These are objects used for injection. Only by injecting these objects can they be used in the following functions
$scope is required for page value transfer
$http is required for http requests
. . .
Module injection, introduce other modules you need to use.
For example, $http is a module