On the code below, as you can see, I subscribe to an observable and on the callback I set status to the value of result
. This is used on an *ngIf on the view. Fact is, even when true is returned, the view is not updated.
export class AppComponent {
private status;
constructor (private proxyService: ProxyService) {
}
ngOnInit(){
//setInterval(()=>console.log(this.isInjected),1000);
this.proxyService.someObservable.subscribe((result)=>{
this.status = result;
console.log(result);
});
}
}
Now, you might notice the commented line. While debugging I added it, and the weird thing is it makes the view update. Any ideas why?
For reference, that is my view:
<div *ngIf="status">
<app-userlane-inject></app-userlane-inject>
</div>
<div *ngIf="!status">
<span>Status is false.</span>
</div>
{{status}}
The child component is never rendered, and the string interpolation remains false even when console logs true (except if the interval is there, then it works).
Here is what the service does in broad terms:
var mySubject= new BehaviorSubject(false);
@Injectable()
export class ProxyService {
public someObservable= mySubject.asObservable();
//Kinda deep callback tree, then finally
mySubject.next(true)
}
Just some extra info to put answers into context: the deep callback chain I mentioned above goes completely out of angular (this was an extension, and the call chain included sending a message to the content script, then to the page, and all the way back). That is why angular zone needs to be called into action again. I didn't know that was the cause, and that is why I didn't include that on my initial question.
var me = this;
. Just usethis.status = result;
ProxyService
? Can you share some code?