Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while entering provider in module ts

While I am trying to import nativepagetransition in providers, it shows an error.

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';
import { LinkPage } from '../pages/link/link';
import { NativePageTransitions } from '@ionic-native/native-page-transitions';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

@NgModule({
declarations: [
MyApp,
HomePage,
LinkPage,


],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
LinkPage

],
providers: [
StatusBar,
SplashScreen,
 NativePageTransitions,


 {provide: ErrorHandler, useClass: IonicErrorHandler}
 ]
 })
 export class AppModule {}

The error is,

Type ‘NativePageTransitionsOriginal’ is not assignable to type ‘Provider’.
Type ‘NativePageTransitionsOriginal’ is missing the following properties from type ‘FactoryProvider’: provide, useFactory [2322]]
like image 465
Gokulanathan KN Avatar asked Jul 24 '26 13:07

Gokulanathan KN


2 Answers

All the native modules and services in ionic 4+ have been move to ngx directory of the module. Like

In ionic 3:

We were importing NativePageTransitions from @ionic-native/native-page-transitions
import { NativePageTransitions } from '@ionic-native/native-page-transitions';

Now in ionic 4+:

We have to import native modules from @ionic-native/module-name/ngx directory.
import { NativePageTransitions } from '@ionic-native/native-page-transitions/ngx';
like image 118
M Shafique Avatar answered Jul 27 '26 03:07

M Shafique


The error comes if you installed the wrong native plugin version for your project type.

Check the project type in ionic.config.json

If the type is "ionic-angular", then install 4.x.x version.

example

npm i -s @ionic-native/[email protected]

If the type is "angular", then install 5.x.x-beta version

npm i -s @ionic-native/[email protected]

Note:

Add ngx at the end of import only if you are using Angular 6

import { NativePageTransitions } from '@ionic-native/native-page-transitions/ngx';

if not remove ngx from the import both in app.module.ts and app.component.ts

import { NativePageTransitions } from '@ionic-native/native-page-transitions';

Refencence:https://github.com/ionic-team/ionic/issues/15225#issuecomment-414074074

like image 40
Rathnakara S Avatar answered Jul 27 '26 02:07

Rathnakara S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!