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

前端之家收集整理的这篇文章主要介绍了angularjs – 为什么我不能在我的config()中注入$location?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么这给我一个错误
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
 });
原文链接:https://www.f2er.com/angularjs/145028.html

猜你在找的Angularjs相关文章