【发布时间】:2019-11-11 16:21:24
【问题描述】:
我将一个自定义确认对话框导入到一个函数中,但除了对话框函数之外,“this”在所有地方都未定义。
这是函数:
onDelete(CTId) {
this.confirmDialogService.confirmThis(
"Confirm Delete",
function() {
this.service.deleteContactDetail(CTId).subscribe(
res => {
this.service.refreshList();
this.toastr.warning("Deleted Successfully", "Contact Details");
},
err => {
console.log(err);
this.toastr.error("Failed to Delete");
}
);
},
function() {
console.log("closed dialog");
}
);
}
对于confirmDialogService,它是这样定义的this: this,而在其他任何地方它都是any
【问题讨论】:
-
将
function() {更改为() => {并阅读一些有关箭头函数的信息(尽管我对this: this感到困惑)。 -
箭头不起作用,表示预期
{ -
抱歉,我把它改成了
function() => {,而不是() => {。真的需要阅读。
标签: angular typescript