I just learned Angular and I am not sure about many things. I have a question and I would like to ask some experts.
There is a run method of the entry function, the code is as follows:
There are some parameters in the run and config parts circled in red boxes. There are two things that are unclear about these parameters:
Question 1: How are these parameters determined? , why these ones and not others? Is the name fixed, or can it be chosen at will?
Question 2: How are these parameters passed?
On the specific controller page, there are also some parameters that I don’t understand how to pass. The code screenshot is as follows:
The same as the two questions above:
Question 1: How are the parameters determined?
Question 2: How are these parameters passed?
1. Angular uses provide to create services (that is, things that can be injected, to put it bluntly, they are provided for other modules to use). A service can define a provider. Whenever you define a provider for a service, the name of the provider is is serviceProvider. Here service is the name of the service. The services corresponding to $httpProvider and $stateProvider in the above picture are $http, $state... These angular built-in services are defined by a serviceProvider at the bottom.
2. After defining the service, we need to use it in the module. To use the service, we first need to reference the dependency on the service, for example: app.controller('xxController', ['xxservice', function(xxservice) {xxx}]) Here xxController references xxservice and then uses it in the module. The bottom layer of angular uses inject to reference the services that modules depend on.
Some angular built-in services ($scope) in Figure 2 can be used without introducing them, and there is another service that needs to be referenced before use ($http, $state...)
You can refer to this article http:/ /sentsin.com/web/663.html
The parameters you mentioned are all services to be injected. Inject those services you need. If these services are not used in your .run, .config, .controller, etc., you don’t need to write them.