I am currently developing user management functionality. When a button is clicked, the goal is to save a new user and display an incoming password stored in the system. Below is a snippet of my code:
onClick() {
/*Code to populate the newUser variable from the form goes here*/
this.store.dispatch(new AddUser(this.newUser))
this.store.select(userFeature.getPassword).subscribe(
pass => {
this.temp = pass; //Previously tried using this.password here with no success
})
setTimeout(() => {
this.pause();
}, 5000);
//this.password = "Stuff" <-- This works correctly
this.password = temp //This executes despite the previous wait
}
pause(){
if(this.temp === null){
setTimeout(() => {
this.pause();
}, 500);
console.log("Waiting...")
}
}
Within my HTML, I utilize {{password}} within a simple span element.
EDIT: Issue resolved! The solution involved using ChangeDetectorRef.
this.store.dispatch(new AddUser(this.newUser))
this.store.select(userFeature.getPassword).subscribe(
pass => {
this.password = pass;
this.cd.detectChanges();
});