I have a ngOnInit() method that fills data list at beginning, I am making two different logic according to there is a query param (navigate back to page) or just first opening of the page. But I have a very weird error at these 2 logic.
In below code:
ngOnInit() {
this.route.queryParams.subscribe((queryParams: Params) => {
this.initFilters(queryParams);
if(this.group) {
this.getActiveGroups();
//console.log(this.activeGroupList);
}
});
this.getActiveGroups();
}
getActiveGroups(): void {
this.service123.getActiveGroups().subscribe((groupData: Group[]) => {
this.activeGroupList = groupData;
//console.log(this.activeGroupList);
})
}
Second comment (console.log line) is working good and logging the list data which comes from backend. But first comment is giving error and saying the variable is undefined. They are same variable but why first one is undefined ? I need that list in first commented part also, so I can use it in functions. Or should i define that variable something like static?
How can I achieve it?