[英]How to call a function in angular2 component from a jquery button click?
[英]Angular2 and jQuery: How to call component level function?
Angular2和jQuery组合使我感到困惑。 请帮忙! 当我调用弹出对话框时,在onApprove情况下,我想调用Component的级别function test()
,但是,这会导致运行时错误:
"TypeError: this.test is not a function"
任何建议表示赞赏!
import { Component, OnInit } from '@angular/core';
declare var $: any;
enter code here
@Component({
selector: 'app-schedule',
templateUrl: './schedule.component.html',
styleUrls: ['./schedule.component.less']
})
export class ScheduleComponent implements OnInit {
scheduled : boolean;
constructor() {
this.scheduled = false;
}
ngOnInit() {
}
test() {
console.log('hello');
}
deleteConfirmDlg() {
$('.mini.modal')
.modal({
closable : false,
onDeny : function(){
window.alert('Wait not yet!');
return false;
},
onApprove : function() {
this.test();
}
}).modal('show');
}
}
您应该使用向右箭头运算符来访问this
deleteConfirmDlg() {
$('.mini.modal')
.modal({
closable : false,
onDeny : function(){
window.alert('Wait not yet!');
return false;
},
onApprove : () => {
this.test();
}
}).modal('show');
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.