Angular2 和 jQuery:如何调用组件级函数?
Angular2 and jQuery: How to call component level function?
Angular2 和 jQuery 组合让我感到困惑。请帮忙!
当我调用弹出对话框和 onApprove 案例时,我想调用组件的级别 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');
}
}
Angular2 和 jQuery 组合让我感到困惑。请帮忙!
当我调用弹出对话框和 onApprove 案例时,我想调用组件的级别 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');
}
}