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
1 Answer
Reset to default 7Try 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
评论列表(0条)