Home  >  Q&A  >  body text

angular.js - 如何理解$provide、provider、$compileProvider等等相关服务

两个代码段的功能是一样的,不同写法主要有什么区别?
$provide,provider,$compileProvider,$controllerProvider,$filterPrivoder,这几个的概念用法区分?

淡淡烟草味淡淡烟草味2690 days ago560

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-15 17:05:57

    I think you want to ask about the role of Provider.
    $provide and $compileProvider in your example are all angular’s ​​internal Providers.
    If you are smart, you have already seen that the call of Provider is in the config. Then you also guessed that the Provider is the configuration of the current application.
    Directive, factory and other modules can be reused in multiple projects, but the environment of each project is different. Calling Provider can configure the environment of the current project.
    For example, when configuring routing, routeProvider is called in config to configure the routing of the project. Each project is different; httpProvider configures the behavior and return content of $http, locationProvider configures whether routing uses #, and so on.
    Custom providers only need to inject (provider name) Provider into the config to call the provider's method.
    By the way, the integrated provider also has a delegate method. If the current project's service requires special functions, it can be added through this, and it will not affect the original service.

    reply
    0
  • Cancelreply