programing

config()에 $location을 삽입할 수 없는 이유는 무엇입니까?

css3 2023. 3. 26. 11:39

config()에 $location을 삽입할 수 없는 이유는 무엇입니까?

에러가 발생하는 이유:

angular.module('app')
       .config(function($routeProvider, $locationProvider, $httpProvider, $location) {

발견되지 않은 오류: 알 수 없는 공급자: 앱에서 $location

근데 이 줄은 안 그래요?

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

같은 앱이에요.할 수 있다config프로바이더만 취득하고factory비균형만 얻을 수 있나요?

컨피규레이션블록에는 프로바이더와 상수만 삽입할 수 있습니다.

설정 블록에 관한 angularjs 매뉴얼 참조

  1. 구성 블록 - 공급자 등록 및 구성 단계에서 실행됩니다.컨피규레이션블록에는 프로바이더와 상수만 삽입할 수 있습니다.이는 서비스가 완전히 구성되기 전에 실수로 인스턴스화되는 것을 방지하기 위한 것입니다.

  2. 실행 블록 - 인젝터가 생성된 후 실행되며 애플리케이션을 킥스타트하는 데 사용됩니다.실행 블록에는 인스턴스와 상수만 주입할 수 있습니다.이는 애플리케이션 실행 시 추가 시스템 구성을 방지하기 위한 것입니다.

기본적으로 컨피규레이션블록은 프로바이더가 컨트롤러, 서비스, 공장 등에 삽입되기 전에 프로바이더를 설정하는 장소입니다.

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
 });

코드를 주입하는 모듈레벨 방법에는 다음 2가지가 있습니다.

1)config이 메서드는 인젝터가 생성되기 전에 실행되며 주입을 위한 공급자와 상수만 받아들입니다.

2)run이 메서드는 앱 초기화 단계에서 실행되며 인스턴스와 상수(예:$location).

factory(그리고service,controller,그리고.directive)는, 애플리케이션의 일부인 기능입니다.이와 같이 이들 역시 인스턴스(또는 싱글톤)와 상수만 받아들일 수 있습니다.

언급URL : https://stackoverflow.com/questions/18137662/why-cant-i-get-a-location-injected-into-in-my-config