2016-08-16 45 views
1

我在我的app.ts中有幾十個進口,經過一個巨大的重構與官方Angular2 styleguide對齊後,我得到了臭名昭着的Invalid Provider Error。我正在使用RC4。Angular2:Howto調試「未捕獲無效提供程序」錯誤?

reflective_provider.js:170Uncaught Invalid provider - only instances of Provider and Type are allowed, got: undefined 

我該如何調試?我需要知道哪些進口/供應商是錯誤的。

這是我進口:

https://gist.github.com/nottinhill/4d61beb9e3a05a6cfc11c65fcb4ad89a

這是我的離子引導:

https://gist.github.com/nottinhill/c8ef4f0f760af2f5a23ebeac35d6113b

+0

你使用什麼版本的角? –

+0

Angular2-RC4 ... – nottinhill

+0

嗯..這應該工作,我猜。嘗試使用'新的提供者(ReservationsService,{useClass:TestService})''而不是'provide'函數。或者,也許這種語法'{提供:LocationStrategy,useClass:HashLocationStrategy}'但我認爲這是用於RC5 –

回答

1

在Angular2-RC4 provide@angular/core已被棄用。你必須定義你的供應商如下:

ionicBootstrap(MyApp, [ 

    GoalService, 
    { 
     provide : TranslateLoader, 
     useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'), 
     deps: [Http] 
    }, 
    TranslateService, 
    { 
     provide : AuthHttp, 
     useFactory: (http) => { 
      return new AuthHttp(
       new AuthConfig(), 
       http 
      ); 
     }, 
     deps: [Http] 
    }, 
    AuthService, 
    AuthServerService, 
    AuthServerMock, 
    AuthZeroService, 
    AuthZeroMock 
]); 
1

根本原因一直循環依賴barell導入下來在我的模塊分層。解決方案是通過'../shared/service/service.service.ts'而不是'../shared/'在導入的模塊和服務中深入導入。

Barell在「../shared/index」更高層次上導入工作正常。

+0

這需要更多的宣傳。一次又一次,這一直是我的服務問題的原因。 – Zze

相關問題