Please i have been trying to implement the Alert component in my ionic project but i keep getting this error (TypeError: Cannot read property ‘present’ of undefined), this happens when i insert the line of code (this.nav.present(alert) at the end and without this code it won’t work. Below is my code
onConfirm() {
let alert = Alert.create({
title: ‘Attention’,
subTitle: ‘hey there’,
buttons: [“Yes”]
})
this.nav.present(alert);
}
The error that is showing on google chrome inspect element is attached
Please help me with solution.
The error message is telling you exactly what is wrong. this.nav
is undefined.
Sorry I don’t understand you when you say this.nav is not define, I think it is defined in the constructor like this (this.nav = nav), or is that not what you are referring to?
undefined
is a primitive value in JavaScript. In the statement you mention, if the right hand side (“nav”) is undefined
, so will be this.nav
. Whereever you are getting nav
from isn’t working.
I just figured where the problem is, in my export class i have something like this
export class AdmissionsPage {
static get parameters() {
return [[Platform]];
}
if i remove the static get parameters() it will work, like this
export class AdmissionsPage {
}.
The problem now is that i can’t remove those parameters because am using it to call inappbrowser plugin, pls do u have any idea on what i can do to keep those parameters and also have the alert working?
If you’re using TypeScript, just type it as a constructor argument:
class AdmissionsPage {
constructor(private _plat:Platform) {
_plat.ready().then(() => {
// do stuff
});
}
anotherMethod() {
// this._plat is still visible here
}
}
If your project is JavaScript, my only advice is “switch to TypeScript”, but perhaps somebody else will have other suggestions. I can’t stand JavaScript, and have done everything in my power to avoid it as much as possible.
ok thanks…i am using typescript, its working now…