首页 > 解决方案 > 在模块 ts 中输入提供程序时出错

问题描述

当我尝试import nativepagetransition在提供程序中时,它显示了一个错误。

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 {}

错误是,

Type ‘NativePageTransitionsOriginal’ is not assignable to type ‘Provider’.
Type ‘NativePageTransitionsOriginal’ is missing the following properties from type ‘FactoryProvider’: provide, useFactory [2322]]

标签: ionic-frameworkionic3ionic-native

解决方案


ionic 4+中的所有本机模块和服务已移至模块的ngx 目录。喜欢

在离子 3 中

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

现在在离子4+:

We have to import native modules from @ionic-native/module-name/ngx directory.
import { NativePageTransitions } from '@ionic-native/native-page-transitions/ngx';

推荐阅读