Using TypeScript and Angular, I have created a function named getTasks()
that I want to fire when a modal is closed. This is the function:
getTasks() {
this.http.get(`https://example.com/_api/web/lists/getbytitle('Tasks')/items`).subscribe(data => {
console.log(data['value'])
this.tasks = data['value']
})
}
I can successfully create my modal with the following:
newTask() {
var options = {
url: `https://example.com/divisions/dev/lists/Tasks/NewForm.aspx?itemParent=${this.itemID}`,
dialogReturnValueCallback: Function['createDelegate'](null, this.newTaskClosed)
}
window.parent['SP'].UI.ModalDialog.showModalDialog(options);
}
This is my callback function that successfully logs when the modal has been closed:
newTaskClosed(result, value) {
console.log(result, value)
this.getTasks(); // Thinks that 'this' is null
}
Running this gives me the following error:
Uncaught TypeError: Cannot read property 'getTasks' of null
How can I solve this?