这是我在Angular / TypeScript应用程序中遇到的有点没用的错误。除非有人使错误消息更好,否则我们该怎么办?导致这种情况发生的最可能情况是什么?这里是我的app.module.js文件和home.ts文件。
当我删除文件和文件打开插件时,没有出现错误。如果我在home.ts中包含该插件,则会显示错误。导致这种情况发生的最可能情况是什么?
app.module.ts:
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 { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { FileOriginal } from '@ionic-native/file';
import { FileOpenerOriginal } from '@ionic-native/file-opener';
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
FileOriginal,
FileOpenerOriginal
]
})
export class AppModule {}
home.ts
import { FileOriginal } from '@ionic-native/file';
import { FileOpenerOriginal } from '@ionic-native/file-opener'
constructor(public navCtrl: NavController,private plt: Platform, private file: FileOriginal, private fileOpener: FileOpenerOriginal) {
}
我遇到了这样的错误:
Uncaught Error: Encountered undefined provider!
Usually this means you have a circular dependencies (might be caused by using 'barrel' index.ts files.)
at syntaxError (compiler.js:486)
at compiler.js:15767
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (compiler.js:15752)
at CompileMetadataResolver.getNgModuleMetadata (compiler.js:15320)
at JitCompiler._loadModules (compiler.js:34413)
at JitCompiler._compileModuleAndComponents (compiler.js:34374)
答案 0 :(得分:0)
您需要使用File而不是FileOriginal。在我的项目中,我声明File为提供者,并且可以正常工作。安装正确吗?
使用此命令ionic cordova plugin add cordova-plugin-file
时,是否有任何依赖项警告?
也许插件的版本与ionic 3不兼容。
编辑
命令:
ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/file@4.2.0