Hello, when I use private filePath: FilePath in the constructor I have the following error. Thank you very much in advance
core.js:9110 ERROR Error: Uncaught (in promise): Error: Can't resolve all parameters for CadastroAnexarComprovantePage: ([object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], ?).
Error: Can't resolve all parameters for CadastroAnexarComprovantePage: ([object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], [object Object], ?).
at syntaxError (compiler.js:2175)
at CompileMetadataResolver._getDependenciesMetadata (compiler.js:20166)
at CompileMetadataResolver._getTypeMetadata (compiler.js:20061)
at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:19690)
at CompileMetadataResolver._getEntryComponentMetadata (compiler.js:20261)
at compiler.js:20253
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getEntryComponentsFromProvider (compiler.js:20252)
at compiler.js:20223
at Array.forEach (<anonymous>)
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:34182)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)
at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:469)
at invokeTask (zone-evergreen.js:1603)
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { HttpService } from '../service/http.service';
import { Camera, CameraOptions, PictureSourceType } from '@ionic-native/camera/ngx';
import { ActionSheetController, ToastController, Platform, LoadingController } from '@ionic/angular';
import { File, FileEntry } from '@ionic-native/File/ngx';
import { WebView } from '@ionic-native/ionic-webview/ngx';
import { Storage } from '@ionic/storage';
import { FilePath } from '@ionic-native/file-path/ngx';
const STORAGE_KEY = 'my_images';
@Component({
selector: 'app-cadastro-anexar-comprovante',
templateUrl: './cadastro-anexar-comprovante.page.html',
styleUrls: ['./cadastro-anexar-comprovante.page.scss'],
})
export class CadastroAnexarComprovantePage implements OnInit {
images = [];
constructor(
private camera: Camera,
private file: File,
private http: HttpService,
private webview: WebView,
private actionSheetController: ActionSheetController,
private toastController: ToastController,
private storage: Storage,
private platform: Platform,
private loadingController: LoadingController,
private ref: ChangeDetectorRef,
private filePath: FilePath
) { }
ngOnInit() {
this.platform.ready().then(() => {
this.loadStoredImages();
});
}
async presentToast(text: string, duration: number) {
const toast = await this.toastController.create({
message: text,
position: 'bottom',
duration
});
toast.present();
}
loadStoredImages() {
this.storage.get(STORAGE_KEY).then(images => {
if (images !== null) {
const arr = JSON.parse(images);
this.images = [];
for (const img of arr) {
const filePath = this.file.dataDirectory + img;
const resPath = this.pathForImage(filePath);
this.images.push({
name: img,
path: resPath,
filePath,
});
}
}
});
}
pathForImage(img: any) {
if (img === null) {
return '';
} else {
const converted = this.webview.convertFileSrc(img);
return converted;
}
}
async selectImage() {
const actionSheet = await this.actionSheetController.create({
header: 'Select Image source',
buttons: [
{
text: 'Carregar da Galeria',
handler: () => {
this.takePicture(this.camera.PictureSourceType.PHOTOLIBRARY);
}
},
{
text: 'Usar a Camera',
handler: () => {
this.takePicture(this.camera.PictureSourceType.CAMERA);
}
},
{
text: 'Cancelar',
role: 'cancel'
}
]
});
await actionSheet.present();
}
takePicture(sourceType: PictureSourceType) {
const options: CameraOptions = {
quality: 100,
sourceType,
saveToPhotoAlbum: false,
correctOrientation: true
};
// this.camera.getPicture(options)
// .then(imagePath => {
// const currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
// const correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
// this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
// });
this.camera.getPicture(options).then(imagePath => {
if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
this.filePath.resolveNativePath(imagePath)
.then((filePath: string) => {
const correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
const currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
});
} else {
const currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
const correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
this.copyFileToLocalDir(correctPath, currentName, this.createFileName());
}
});
}
copyFileToLocalDir(namePath: any, currentName: any, newFileName: any) {
this.file.copyFile(namePath, currentName, this.file.dataDirectory, newFileName).then(_ => {
this.updateStorageImage(newFileName);
}, error => {
this.presentToast('Erro ao carregar o arquivo', 2000);
});
}
createFileName() {
const d = new Date(),
n = d.getTime(),
newFilename = n + '.jpg';
return newFilename;
}
updateStorageImage(name: any) {
this.storage.get(STORAGE_KEY).then(images => {
const arr = JSON.parse(images);
if (!arr) {
const newImages = [name];
this.storage.set(STORAGE_KEY, JSON.stringify(newImages));
} else {
arr.push(name);
this.storage.set(STORAGE_KEY, JSON.stringify(arr));
}
const filePath = this.file.dataDirectory + name;
const resPath = this.pathForImage(filePath);
const newEntry = {
name,
path: resPath,
filePath
};
this.images = [newEntry, ...this.images];
this.ref.detectChanges();
});
}
deleteImage(imgEntry: any, position: any) {
this.images.splice(position, 1);
this.storage.get(STORAGE_KEY).then(images => {
const arr = JSON.parse(images);
const filtered = arr.filter(name => name !== imgEntry.name);
this.storage.set(STORAGE_KEY, JSON.stringify(filtered));
const correctPath = imgEntry.filePath.substr(0, imgEntry.filePath.lastIndexOf('/') + 1);
this.file.removeFile(correctPath, imgEntry.name).then(res => {
this.presentToast('Arquivo removido.', 2000);
});
});
}
startUpload(imgEntry: any) {
this.file.resolveLocalFilesystemUrl(imgEntry.filePath)
.then(entry => {
(entry as FileEntry).file(file => this.readFile(file));
})
.catch(err => {
this.presentToast('Erro ao ler o arquivo.', 2000);
});
}
readFile(file: any) {
console.log(file);
const reader = new FileReader();
reader.onloadend = () => {
const imgBlob = new Blob([reader.result], {
type: file.type
});
const formData = new FormData();
formData.append('file', imgBlob, file.name);
this.uploadImageData(formData);
};
reader.readAsArrayBuffer(file);
}
async uploadImageData(formData: FormData) {
/* (await this.http.uploadImageData(formData))
.subscribe(res => {
''
if (res.success) {
this.presentToast(res.message, 2000);
} else {
this.presentToast(res.message, 2000);
}
});*/
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { HttpClientModule } from '@angular/common/http';
import { File } from '@ionic-native/File/ngx';
import { FileOpener } from '@ionic-native/file-opener/ngx';
import { FileTransfer } from '@ionic-native/file-transfer/ngx';
import { DocumentViewer } from '@ionic-native/document-viewer/ngx';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';
import { DatabaseService } from './service/database.service';
import { Keyboard } from '@ionic-native/keyboard/ngx';
import { InAppBrowser } from '@ionic-native/in-app-browser/ngx';
import { AppVersion } from '@ionic-native/app-version/ngx';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { FCM } from '@ionic-native/fcm/ngx';
import { Clipboard } from '@ionic-native/Clipboard/ngx';
import { IonicStorageModule } from '@ionic/storage';
import { Camera } from '@ionic-native/camera/ngx';
import { WebView } from '@ionic-native/ionic-webview/ngx';
import { FilePath } from '@ionic-native/file-path/ngx';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpClientModule,
IonicStorageModule.forRoot(),
],
providers: [
StatusBar,
SplashScreen,
Keyboard,
AppVersion,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
File,
FileOpener,
// tslint:disable-next-line: deprecation
FileTransfer,
DocumentViewer,
SQLite,
DatabaseService,
InAppBrowser,
Geolocation,
FCM,
Clipboard,
Camera,
WebView,
FilePath
],
bootstrap: [AppComponent]
})
export class AppModule { }
Ionic:
Ionic CLI : 6.2.0 (C:\Users\jonathan.brambati\AppData\Roaming\npm\node_modules\@ionic\cli)
Ionic Framework : @ionic/angular 4.11.10
@angular-devkit/build-angular : 0.803.25
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.0.0
Cordova:
Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.1.3, (and 16 other plugins)
Utility:
cordova-res : 0.9.0
native-run : 0.3.0
System:
Android SDK Tools : 26.1.1 (C:\Users\jonathan.brambati\AppData\Local\Android\Sdk)
NodeJS : v12.16.0 (C:\Program Files\nodejs\node.exe)
npm : 6.13.7
OS : Windows 10