One of the challenges I am facing is having a method that needs to be called in different parts of my component. The method looks like this:
this.updateResults();
This method depends on certain properties of the component. While it works fine when called from template methods, I want it to also work after the queryParams are changed. To achieve this, I added the following code:
ngOnInit() {
this.navigationSubscription = this._router.events.subscribe((e: any) => {
if (e instanceof NavigationEnd) {
this.updateResults();
}
});
}
The method runs at the expected time, but I noticed that the required properties are null when it is executed.
When I check in the debugger, the component appears as _this
instead of this
. This might be why this.propertyName
is not working as intended.
It seems like the component is out of scope when the method is called. How can I ensure that this method call remains within the scope of the component?