angular - Call angular2 method from javascript function - Stack Overflow

I am using jquery kendo ui grid and from that edit button i am trying to call angular2 method. My setup

I am using jquery kendo ui grid and from that edit button i am trying to call 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
   });
}
}

It's working code the only issue is this. I can call the angular2 method by just stating

 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

I am using jquery kendo ui grid and from that edit button i am trying to call 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
   });
}
}

It's working code the only issue is this. I can call the angular2 method by just stating

 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

Share Improve this question edited Dec 20, 2017 at 12:55 Oleksii Pavlenko 1,3331 gold badge12 silver badges25 bronze badges asked Nov 3, 2015 at 2:56 NavinNavin 7442 gold badges11 silver badges27 bronze badges 2
  • all Angular methods are JavaScript, so your question title doesn't even make sense. – Claies Commented Nov 3, 2015 at 3:10
  • Yes all angular methods are javascrupt but my title "angular2 method " by this i mean the method of an instance. because if you just call this.edit it wont execute the method from the current instance. – Navin Commented Nov 3, 2015 at 4:19
Add a ment  | 

1 Answer 1

Reset to default 7

Try something like this

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

or

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744682952a4587741.html

相关推荐

  • angular - Call angular2 method from javascript function - Stack Overflow

    I am using jquery kendo ui grid and from that edit button i am trying to call angular2 method. My setup

    1天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信