简体   繁体   English

从javascript函数调用angular2方法

[英]Call angular2 method from javascript function

I am using jquery kendo ui grid and from that edit button i am trying to call angular2 method. 我正在使用jquery kendo ui grid并从该编辑按钮我试图调用angular2方法。 My setup is simple: 我的设置很简单:

export class UserComponent implements OnInit {
     constructor( @Inject(UserService) public userService: UserService,  @Inject(FormBuilder) public fb: FormBuilder) {
...
}


 edit():void{ }

 onInit() {
   $("#grid").kendoGrid({
   ....
   click: function () {
     // Call angular2 method of the current instance
   });
}
}

It's working code the only issue is this. 它的工作代码是唯一的问题。 I can call the angular2 method by just stating 我可以通过陈述来调用angular2方法

 click:this.edit

or 要么

 click: function () {
         UserComponent.prototype.edit()
       });

but in both case the method is not from the current instance. 但在这两种情况下,该方法都不是来自当前实例。 So in this case i cannot make use of the http service or any local variable or methods inside edit 所以在这种情况下我无法使用http服务或任何局部变量或编辑内的方法

Try something like this 尝试这样的事情

click: function () {
   this.edit();
}).bind(this);

or 要么

var self = this;
$("#grid").kendoGrid({

   click: function () {
     self.edit();
   });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM