Answer the question
In order to leave comments, you need to log in
How to update template from observable?
Hello.
Help solve the problem.
Here is what I have in the component
export class DashboardComponent implements OnInit {
username: String = 'hello ';
constructor(private userdata: UserdataService) { } // здесь у меня сервис, где написано: user = new Subject();
ngOnInit() {
this.userdata.user.subscribe( (datatest: string) => {
this.username = datatest;
console.log(this.username);
});
}
}
Answer the question
In order to leave comments, you need to log in
from the code, it looks like the ngOnInit method only subscribes to the this.userdata.user change.
Those. you are not executing code from subscribe, but simply signing an agreement that you will execute it if the this.userdata.user variable changes.
but the code doesn't show you changing this.userdata.user.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question