错误:无法解析FirebaseDataService的所有参数

时间:2017-11-29 07:22:15

标签: angular dependency-injection angularfire2

我一直试图通过以下设置来抽象和隐藏我的DataService的实现:

的DataService:

import { Observable } from 'rxjs/Observable';

export abstract class DataService {
    abstract getMyData(): Observable<any>;
}

FirebaseDataService:

import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';

import { DataService } from './data.service';
import { MyData } from '../mydata/mydata.model';

export class FirebaseDataService extends DataService {
  constructor(private db: AngularFireDatabase) {
    super();
  }

  getMyData(): Observable<any> {
    return this.db.list(MyData.name).valueChanges();
  }
}

DataModule的:

import { NgModule } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';

import { DataService } from './data.service';
import { FirebaseDataService } from './firebase-data.service';
import { environment } from '../../environments/environment';

@NgModule({
  imports: [
    AngularFireModule.initializeApp(environment.firebase),
    AngularFireDatabaseModule
  ],
  providers: [
    { provide: DataService, useClass: FirebaseDataService }
  ]
})
export class DataModule { }

在另一个模块中,我导入DataModule并调用DataService方法,如下所示:

@Injectable()
export class MyDataEffects {
  @Effect()
  getMyData = this.actions$
    .ofType(MyDataActions.GET_MYDATA)
    .switchMap((action: MyDataActions.GetMyData) => this.db.getMyData())
    .map( mydata => ({ type: MyDataActions.SET_MYDATA, payload: mydata }));

  constructor(
    private actions$: Actions,
    private db: DataService,
    private store: Store<fromMyData.FeatureState>) { }
}

运行此代码后,浏览器会记录一个&#34;无法解析FirebaseDataService的所有参数&#34;错误信息。这听起来像是一个依赖注入问题,但我还没能弄清楚确切的问题是什么。

这是一个Angular bug还是我错过了什么?感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

从 -

更改此内容
import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';

import { DataService } from './data.service';
import { MyData } from '../mydata/mydata.model';

export class FirebaseDataService extends DataService

import { AngularFireDatabase } from 'angularfire2/database';
import { Observable } from 'rxjs/Observable';
import {Injectable} from '@angular/core';
import { DataService } from './data.service';
import { MyData } from '../mydata/mydata.model';

@Injectable()
export class FirebaseDataService extends DataService