加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 为什么我不能在我的config()中注入$location?

发布时间:2020-12-17 08:24:36 所属栏目:安全 来源:网络整理
导读:为什么这给我一个错误: angular.module('app').config(function($routeProvider,$locationProvider,$httpProvider,$location) { Uncaught Error: Unknown provider: $location from app 但这行不行? angular.module("app").factory("SomeResource",functio
为什么这给我一个错误:
angular.module('app').config(function($routeProvider,$locationProvider,$httpProvider,$location) {

Uncaught Error: Unknown provider: $location from app

但这行不行?

angular.module("app").factory("SomeResource",function($q,$resource,$http,$location,AuthenticationService,Base64) {

这是同一个应用程序可以配置只能获得提供者,工厂只能获得非提供者?

只有提供者和常量可能被注入到配置块中。

From the angularjs 07000 on configuration blocks

  1. Configuration blocks – get executed during the provider registrations and configuration phase. Only providers and constants can be injected into configuration blocks. This is to prevent accidental instantiation of services before they have been fully configured

  2. Run blocks – get executed after the injector is created and are used to kickstart the application. Only instances and constants can be injected into run blocks. This is to prevent further system configuration during application run time.

配置块基本上是在将提供者注入控制器,服务,工厂等之前配置的地方。

angular.module('myModule',[]).
 config(function(injectables) { // provider-injector
   // This is an example of config block.
   // You can have as many of these as you want.
   // You can only inject Providers (not instances)
   // into the config blocks.
 }).
 run(function(injectables) { // instance-injector
   // This is an example of a run block.
   // You can have as many of these as you want.
   // You can only inject instances (not Providers)
   // into the run blocks
 });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读