search

Home  >  Q&A  >  body text

angular.js - angular参数问题

刚学习angular,很多地方不清楚,有个问题请教一下各位大神。
有一个入口函数的run方法,代码如下:


被红框圈出来的部分run和config里面有些参数,关于这些参数有两个地方不清楚:
问题1:这些参数是怎么确定的,为什么是这几个而不是其它的?名字是固定的吗,还是可以随意起?
问题2:这些参数是怎么传递过来的?

在具体的controller页面也一样有些参数不明白它是怎么传递的,代码截图如下:


和上面的两个疑问是一样的:
问题1:参数怎么确定的?
问题2:这些参数是怎么传递过来的?

高洛峰高洛峰2743 days ago525

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-15 17:15:30

    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

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-15 17:15:30

    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.

    reply
    0
  • Cancelreply