The XService type is not assigned to the FactoryProvider type. Missing 'provide' property

I have an Angular 2 NgModule in an Ionic 2 mobile app defined like this:

 @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 is defined as follows:

 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 get the following runtime error:

The typeof type VatRatesDbService cannot be assigned to the FactoryProvider type. The property 'provide' is missing in the type 'typeof VatRatesDbService' type.

+6
source share
3 answers

The solution is to remove the private modifier from the constructor. You simply cannot have an injection 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' }); } 
+12
source

Source Link

I encountered this problem in the latest version 4.9.0 for CLI Ionic.

When I created an older version of the Ionic 3 application in the latest CLI and installed the Native plugin version , I encountered this error

[ts] The type 'AppVersionOriginal' cannot be assigned to the type 'Provider'. The type 'AppVersionOriginal' lacks the following properties from the type 'FactoryProvider': provide, use the factory [2322]

for this we need to install an older version of the native plugin

0
source

This is due to the latest ion update for ion 4.

You should import it like this (by adding '/ ngx')

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

Or you can downgrade the plugin

This happened to me with another plugin.

More info here

0
source

Source: https://habr.com/ru/post/1264042/


All Articles