I\'m building a site that has a pretty standard RESTful web service to handle persistence and complex business logic. The UI I\'m building to consume this service is using A
For your first problem solution is to use arrow function which will preserve context of this :
onGoogleLoginSuccess = (loggedInUser) => {
this.userAuthToken = loggedInUser.getAuthResponse().id_token;
this.userDisplayName = loggedInUser.getBasicProfile().getName();
console.log(this);
}
Second issue is happening because third-party scripts run outside the context of Angular. Angular uses zones so when you run something, for example setTimeout(), which is monkey-patched to run in the zone, Angular will get notified. You would run jQuery in zone like this:
constructor(private zone: NgZone) {
this.zone.run(() => {
$.proxy(this.onGoogleLoginSuccess, this);
});
}
There are many questions/answers about the zone with much better explanations then mine, if you want to know more, but it shouldn't be an issue for your example if you use arrow function.