为什么我不能得到我的配置注入$位置()? [英] Why can't I get a $location injected into in my config()?
问题描述
为什么这个给我一个错误:
angular.module(应用)。配置(函数($ routeProvider,$ locationProvider,$ httpProvider,$位置){
未捕获的错误:未知提供商:从应用$位置
块引用>但是,这行不?
angular.module(应用程序)。工厂(SomeResource功能($ Q $资源,$ HTTP,$位置的AuthenticationService,基数64){
这是相同的应用程序。可以通过
配置
只得到供应商和工厂
只能获得非供应商?解决方案只有供应商和常量可以被注入到配置块。
从上配置块angularjs 文档
配置块 - 在供应商登记和配置阶段得到执行。只有供应商和常量可以被注入到配置块。这是prevent服务的意外实例,他们已经完全配置之前
运行块 - 创建喷油器后得到执行,用于kickstart的应用程序。只有实例和常量可注入运行块。这是prevent进一步的系统配置过程中应用程序的运行时间。
块引用>基本上的配置部分,可以配置它们提供注入控制器,服务,工厂前等。
angular.module(MyModule的,[])。
配置(功能(注射剂){//提供商注射器
//这是配置块的一个例子。
//你可以有很多这样的,只要你想。
//只能注入提供商(不是实例)
//进入配置块。
})。
运行(功能(注射剂){//例如注射器
//这是一个运行块的一个例子。
//你可以有很多这样的,只要你想。
//只能注入情况下(不提供)
//到运行块
});Why does this give me an error:
angular.module('app').config(function($routeProvider, $locationProvider, $httpProvider, $location) {
Uncaught Error: Unknown provider: $location from app
But this line doesn't?
angular.module("app").factory("SomeResource", function($q, $resource, $http, $location, AuthenticationService, Base64) {
It's the same app. Can
config
only get providers andfactory
only get non-providers?解决方案Only providers and constants may be injected into configuration blocks.
From the angularjs documentation on configuration blocks
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
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.
Essentially the configuration block is where you configure providers before they are injected into controller, services, factories and so on.
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 });
这篇关于为什么我不能得到我的配置注入$位置()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!