Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeof XService is not assignable to type 'FactoryProvider'. Property 'provide' is missing

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 at runtime:

Type 'typeof VatRatesDbService' is not assignable to type 'FactoryProvider'. Property 'provide' is missing in type 'typeof VatRatesDbService'.

like image 725
kosiara - Bartosz Kosarzycki Avatar asked Feb 09 '17 21:02

kosiara - Bartosz Kosarzycki


2 Answers

It happens because of ionic latest update for ionic 4.

You have to import it like this (adding '/ngx' )

import { PluginName} from '@ionic-native/pluginName/ngx';

Or, you can downgrade the plugin's version

It was happening to me with another plugin.

More info here

like image 151
Blast06 Avatar answered Sep 28 '22 09:09

Blast06


It work for me In Ionic 4

You have to import it like this (adding '/ngx' )

import { PluginName} from '@ionic-native/pluginName/ngx';

like image 44
Naveen Patel Avatar answered Sep 28 '22 08:09

Naveen Patel