In TypeScript and Angular, I've developed a function called getTasks()
that should run when a modal is closed. Here's the code for 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'm able to create my modal successfully using 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 the callback function that logs when the modal is closed:
newTaskClosed(result, value) {
console.log(result, value)
this.getTasks(); // 'this' appears as null here
}
But executing this code results in the error:
Uncaught TypeError: Cannot read property 'getTasks' of null
Any ideas on how to fix this issue?