This is an example of an alert service in TypeScript
public Alert = {
prompt: () => {
return new Promise((resolve, reject) => {
let prompt = this.alertCtrl.create({
title: 'Enter username',
inputs: [
{
name: 'username',
placeholder: 'Username'
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
reject(false);
}
},
{
text: 'Save',
handler: data => {
console.log(data);
resolve(data);
}
}
]
});
prompt.present();
});
}
}
This is how the request service uses the Alert function:
function () {
this.prompt.Alert.prompt().then((res) => {
this.user.username = res;
alert(this.user.username);
}, err => {
this.alertService.Alert.alert('user_cancelled', 'Error');
});
}
While this code works in the browser using IONIC Serve, it seems to have issues on a device. I'm encountering an error that says "Can not read property 'prompt' of undefined".