Мне нужно передать путь сохраненного изображения в новый компонент, но я не могу получить его из условия if
. Это мой код:
public imagePath: string;
constructor() {}
async selectPhoto(): Promise<any> {
let context = imagepicker.create({
mode: "single"
});
await context.authorize();
const selection = await context.present();
const source = new ImageSource();
source.fromAsset(selection[0])
.then((imageSource: ImageSource) => {
const folderPath: string = knownFolders.documents().path;
const fileName = 'img_' + new Date().getTime()+ '.jpg';
const filePath = path.join(folderPath, fileName);
console.log('Path: ',filePath);
const saved: boolean = imageSource.saveToFile(filePath, "jpg");
if (saved) {
console.log("Image saved");
this.imagePath = filePath;
}
})
.catch((e) => {
console.log("Error ");
console.log(e);
});
console.log("New path: ", this.imagePath);
return selection[0];
}
Я попытался сделать сохранение изображения как отдельную функцию и получить filePath
, но это не работает. console.log("New path: ", this.imagePath)
ошибка возврата: Новый путь: не определено