I'm trying to set a flag in my component to know if the view is loaded by the user clicking on the "Previous page" button of the browser.
The "fromBackButton" attribute is set to false when is defined in the component.
In the constructor I have this code:
this.location.subscribe((popStateEvent: PopStateEvent) => {
// Detect popstate
if (popStateEvent.type === 'popstate') {
this.fromBackButton = true;
}
});
If I put console.log(this.fromBackButton) in the ngOnInit or in any other method, the value is False.
I've tried using
this.changeDetectorRef.markForCheck();
and
this.changeDetectorRef.detectChanges();
after setting the flag to "True", and also tried to use ngZone.run(), but I get the same result