Angular2 Ionic2无法解析GameServiceProvider的所有参数:(?)

时间:2017-07-09 11:51:03

标签: angular ionic-framework

Runtime Error
Can't resolve all parameters for GameServiceProvider: (?).

Error: Can't resolve all parameters for GameServiceProvider: (?).
    at syntaxError (http://localhost:8100/build/main.js:78899:34)
    at CompileMetadataResolver._getDependenciesMetadata (http://localhost:8100/build/main.js:92236:35)
    at CompileMetadataResolver._getTypeMetadata (http://localhost:8100/build/main.js:92104:26)
    at CompileMetadataResolver._getInjectableMetadata (http://localhost:8100/build/main.js:92090:21)
    at CompileMetadataResolver.getProviderMetadata (http://localhost:8100/build/main.js:92380:40)
    at http://localhost:8100/build/main.js:92309:49
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver._getProvidersMetadata (http://localhost:8100/build/main.js:92270:19)
    at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:8100/build/main.js:91700:30)
    at CompileMetadataResolver._getEntryComponentMetadata (http://localhost:8100/build/main.js:92357:45)

我有两个供应商机器人和游戏服务
这是我在提供商/游戏服务/游戏服务中的游戏服务提供商。

import { Injectable } from '@angular/core';
import { Component } from '@angular/core';
import { BotProvider } from '../bot/bot';
@Component({
  providers: [BotProvider]
})
 @Injectable()
export class GameServiceProvider {
	... vars i have to use some in Botprovider aswell ...
	constructor(public bot: BotProvider){
	}
	... functions ...
}

这是我在提供商/ bot / bot.ts中的bot提供程序

import { Injectable, Component } from '@angular/core';
import { GameServiceProvider } from '../game-service/game-service';
@Component({
  providers: [GameServiceProvider]
})
@Injectable()
export class BotProvider {
	constructor(public gs: GameServiceProvider) {}
	.. functions ..
}

通过ionic generate provider {{NAME}}

创建的地方

我的app.compoment.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { BotProvider } from '../providers/bot/bot';
import { GameServiceProvider } from '../providers/game-service/game-service';


import { LoginPage } from '../pages/login/login';
import { HomePage } from '../pages/home/home';
@Component({
  templateUrl: 'app.html',
  providers: [GameServiceProvider,BotProvider]
})
export class MyApp {
  rootPage:any = HomePage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });
  }

我的app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { MaterialModule } from '@angular/material';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { GooglePlus } from '@ionic-native/google-plus';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { GamePage } from '../pages/game/game';
import { LoginPage } from '../pages/login/login';
import { BotProvider } from '../providers/bot/bot';
import { GameServiceProvider } from '../providers/game-service/game-service';

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    GamePage,
    LoginPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    MaterialModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    GamePage,
    LoginPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    GooglePlus,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    BotProvider,
    GameServiceProvider
  ]
})
export class AppModule {}

我应该写另一个提供商,其中只包含提供商需要的东西,或者一个提供商可能在其构造函数中有提供者,反之亦然

周末愉快!

1 个答案:

答案 0 :(得分:2)

GameServiceProvider对象有多个引用,

  • 的AppModule
  • BotProvider
  • MyApp的

删除每个文件中的提供程序块,并将其全局包含在AppModule