Call angular2 method from javascript function

I am using the jquery kendo ui grid, and from this edit button I am trying to call the angular2 method. 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
   });
}
}

This working code is the only problem. I can call the angular2 method by simply specifying

 click:this.edit

or

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

but in both cases the method is not from the current instance. So in this case, I cannot use the http service or any local variable or methods inside edit

+4
source share
1 answer

Try something like this

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

or

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

   click: function () {
     self.edit();
   });
+7
source

Source: https://habr.com/ru/post/1614214/


All Articles