Hi,
I am a bit onfused about the scope of providers and/pr injectables;
I wanted to build a provider wrapping some often used stuff, like a confirmation dialog before deleting, which initializes the deletion when confirmed.
My code in the provider:
constructor(public alertCtrl: AlertController) { }
ShowConfirmation(title, message, ok, okText, cancelText) {
let confirm = this.alertCtrl.create({
title: title,
message: message,
buttons: [
{
text: cancelText,
role: 'cancel',
handler: () => {
// nothing
}
},
{
text: okText,
role: 'cancel',
handler: () => {
ok();
}
}
]
});
confirm.present();
}
the call:
this.utils.ShowConfirmation("Delete", "Do you really want to delete this item?", this.deleteItem, "Delete", "Cancel");
the deleteItem()
deleteItem() {
let idx = this.items.findIndex(x => x.MD5 == this.key);
if (idx != -1) {
this.items.splice(idx, 1);
this.Data.storage.set('myItems', JSON.stringify(this.items)).then(() => {
this.refreshData();
});
}
}
The error I get: Cannot read property ‘items’ of undefined
Okay, so the page from wher I call the method is not in the scope. Why? Amd how do I do this correctly? How do I get the correct scope in a provider?
thnx