Why Angular component variable inside subscribe function undefined right after initialization in Typescript?
I have an Angular ngOnInit event like this:
ngOnInit() {
this.dataService.getData('goods', {}).subscribe(data => {
this.gridDataSource = new DataSource({ store: { type: 'array', data: data }});
this.selectedRows = [data[0]];
});
}
If I put a breakpoint in WebStorm on the 'this.selectedRows' line and the breakpoint gets hit, WebStorm shows this.gridDataSource as undefined. 'this' is safeSubscribe.
Why is it undefined?
Please sign in to leave a comment.
This is the issue with sourcemaps generated when transpiling the code; please check the answer at https://developercommunity.visualstudio.com/content/problem/555338/angular-typescript-class-objects-not-accessible-in.html
Related Typescript ticket: https://github.com/Microsoft/TypeScript/issues/9627
Thanks. That was helpful.