Vote count: 0
I have an Angular 2 NgModule in a Ionic 2 mobile app defined like so:
@NgModule({
declarations: [
MyApp,
HomePage,
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
],
providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}, VatRatesDbService]
})
export class AppModule {}
and the service defined this way:
import { Injectable } from '@angular/core';
import * as PouchDB from 'pouchdb';
@Injectable()
export class VatRatesDbService {
private _db;
private constructor() {
this._db = new PouchDB('rates.db', { adapter: 'websql' });
}
}
however, I'm getting the following error on runtime - Type 'typeof VatRatesDbService' is not assignable to type 'FactoryProvider'. Property 'provide' is missing in type 'typeof VatRatesDbService'.
asked 1 min ago
1 Answer
Vote count: 0
The solution is to remove the private modifier from the constructor. You simply cannot have an injectable service with a private constuctor.
public constructor() {
this._db = new PouchDB('rates.db', { adapter: 'websql' });
}
or:
constructor() {
this._db = new PouchDB('rates.db', { adapter: 'websql' });
}
answered 1 min ago
typeof XService is not assignable to type 'FactoryProvider'. Property 'provide' is missing
Aucun commentaire:
Enregistrer un commentaire