I have a subscribe statement and I am trying to debug this however when I step through in VS Code 'this' is always undefined inside the statement. In this situation 'this.dataLoaded' is undefined. how can I get it to not be undefined when debugging?
this.router.events
.filter(event => (event instanceof NavigationEnd))
.subscribe((routeData: any) => {
if(!this.dataLoaded){
...
}
});
Please have a look on closure
expand sections in debugger variables
tab. Your real this
will be one level above the top-most, where this
is referred to component controller name. Each anonymous function creates additional closure, in your case it's enclosed in subscribe
, ant this closure will be opened by default by VS Code when your breakpoint will be hit.
And please try to avoid this old-style JS hacking let that = this
e.c.t, because when you on TypeScript, Classes, ES6 and arrow functions those hacks are just not needed anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With