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? 

0
2 comments

Thanks. That was helpful.

0

Please sign in to leave a comment.