1

hy。我剛剛將我的應用程序更新爲角度4.4.3和最新的角度材質。之後萬噸的錯誤,現在我只有一次,但看起來有點混亂,因爲這是很難理解什麼是文件錯誤的名稱在 我得到錯誤:如何找到包含錯誤的文件?

(SystemJS) Invalid provider - only instances of Provider and Type are allowed, got: [object Object] 
    Error: Invalid provider - only instances of Provider and Type are allowed, got: [object Object] 
     at invalidProviderError (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:1317:12) 
     at eval (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2118:19) 
     at Array.forEach (<anonymous>) 
     at _normalizeProviders (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2107:15) 
     at eval (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2115:13) 
     at Array.forEach (<anonymous>) 
     at _normalizeProviders (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2107:15) 
     at resolveReflectiveProviders (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2058:39) 
     at Function.ReflectiveInjector.resolve (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2287:16) 
     at Function.ReflectiveInjector.resolveAndCreate (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2319:79) 
    Evaluating http://localhost:8080/main.js 
    Error loading http://localhost:8080/main.js 
     at invalidProviderError (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:1317:12) 
     at eval (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2118:19) 
     at Array.forEach (<anonymous>) 
     at _normalizeProviders (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2107:15) 
     at eval (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2115:13) 
     at Array.forEach (<anonymous>) 
     at _normalizeProviders (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2107:15) 
     at resolveReflectiveProviders (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2058:39) 
     at Function.ReflectiveInjector.resolve (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2287:16) 
     at Function.ReflectiveInjector.resolveAndCreate (http://localhost:8080/node_modules/@angular/core/bundles/core.umd.js:2319:79) 
    Evaluating http://localhost:8080/main.js 
    Error loading http://localhost:8080/main.js 

你能幫助我嗎?錯誤在哪裏? 我認爲錯誤是在文件main.ts,但是隻有短短的幾行:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 
import { AppModule } from './app/app.module'; 
platformBrowserDynamic().bootstrapModule(AppModule); 

有在AppModule只有一個地方可以與providers有關:

//changes languages that are set locally 
import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; 


@NgModule({ 
    imports: [..., 

TranslateModule.forRoot({ 

      loader: { 
       provide: TranslateLoader, 
       useFactory: HttpLoaderFactory, 
       deps: [Http] 
      } 

     }) 

而且,還有其他地方在路由的其他組件文件中:

//used for listing json as treeview 
import { 
    TreeviewI18n, 
    TreeviewItem, TreeviewConfig, 
    TreeviewHelper, 
    TreeviewComponent, 
    TreeviewEventParser, OrderDownlineTreeviewEventParser, 
    DownlineTreeviewItem 
} from 'ngx-treeview'; 


@Component({ 

    selector: '...', 

    templateUrl: '...', 

    providers: [HttpService, 
     { provide: TreeviewEventParser, useClass: OrderDownlineTreeviewEventParser } 
    ] 


}) 
+0

您遇到了無效提供程序的問題,此對象需要[對象對象]。但是添加你的代碼,因爲這不是一個答案,它只是調試錯誤所說的。 – 2017-10-09 07:55:48

+0

問題出在你的AppModule裏面,你在你的AppModules提供者數組中添加了一個錯誤的東西。發佈你的'AppModule'的代碼 – PierreDuc

+0

@PierreDuc你能看到我更新的帖子嗎? – AmoT

回答

1

檢查模塊中的提供程序 - 您可能傳遞對象而不是提供程序類。