0
Hi, I have the following code:
export class Page {
constructor(public modalController: ModalController) { }
private async openModal(value) {
const modal = await this.modalController.create({
component: AnotherPage,
componentProps: {
"paramID": 123,
"paramTitle": "Test Title",
"takenPhoto": "null"
}
});
return await modal.present();
}
public async takePicture() {
this.openModel(null); // aqui dá certo
Promise.resolve(this.someMethod()).then(this.openModal); // aqui dá erro
}
}
In the method takePicture
i want to open a modal after running the Promise.resolve
. In the first execution of the function everything works well, but in the second gives error.
That is the mistake:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'modalController' of undefined
TypeError: Cannot read property 'modalController' of undefined
at tab2.page.ts:25
at Generator.next (<anonymous>)
at tslib.es6.js:73
at new ZoneAwarePromise (zone-evergreen.js:876)
at Module.__awaiter (tslib.es6.js:69)
at openModal (tab2.page.ts:22)
at ZoneDelegate.invoke (zone-evergreen.js:359)
at Object.onInvoke (core.js:34201)
at ZoneDelegate.invoke (zone-evergreen.js:358)
at Zone.run (zone-evergreen.js:124)
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)
Anyone know how to handle it? Thank you.