所以我在我的应用中使用了uikit confirmation modal。我的问题是,当我要点击<button>
进行确认时。内部函数this
为undefined
。这是我的代码......
declare var UIkit:any;
deleteData(dataArr): void {
UIkit.modal.confirm('Are you sure you want to delete this?', function() {
console.log(dataArr);
console.log(this);
//use service here...
UIkit.modal.alert('Confirmed!');
});
}
在该函数内部我希望使用http请求服务,但我在this
上遇到问题。我正在使用Angular 2.x.
答案 0 :(得分:5)
答案 1 :(得分:0)
'this'未传递到您的功能范围,请尝试
declare var UIkit:any;
deleteData(dataArr): void {
var that = this;
UIkit.modal.confirm('Are you sure you want to delete this?', function(){
console.log(dataArr);
console.log(that);
//use service here...
UIkit.modal.alert('Confirmed!');
});
}