I am currently working on the following task:
class User {
name: string;
userService: UserService; //service responsible for fetching data from server
successCallback(response: any) {
this.name = string;
}
setUser() {
var xhr: JQueryXHR = this.userService.fetchUser(); //Returns JQueryXHR object
xhr.then(this.successCallback);
}
}
When I invoke the setUser method on an instance of the User class:
var user: User = new User();
user.setUser();
The issue is that this.name
in successCallback
is returning undefined.
Is there a way to reference the attribute of the class within the callback function?