alert-service.ts
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();
});
}
}
request-service.ts
function () {
this.prompt.Alert.prompt().then((res) => {
this.user.username = res;
alert(this.user.username);
}, err => {
this.alertService.Alert.alert('user_cancelled', 'Error');
});
}
This runs in the browser when I use IONIC Serve, but it's not working on a device. I'm getting Can not read property 'prompt' of undefined