I have a component that calls on an endpoint to populate a variable of type List which is a List of PaperNames.
papers: paperNameDTO;
I populate papers on the page loading in ngOnInit:
ngOnInit() {
this.fileService.getPaperNames().subscribe(data => {
console.log('Entering here API call');
this.papers = data['papers'];
});
if(this.papers.papersList.length > 0) {
console.log('Entering filteredPapers');
const filteredPapers = this.papers.papersList.filter(paper => paper.name
!== 'FINAL_YEAR' && paper.name !== 'FIRST_YEAR' );
console.log('Final length is = ' + filteredPapers.length);
}
}
The goal is to exclude returned Strings with names 'FINAL_YEAR' and 'FIRST_YEAR' which i filter into another array of Strings.
Problem i face is this method does not work, when i check the console logs, the
loop if(this.tables.tables.length > 0)
gets entered first before this.enquireService.getTableNames().subscribe(data =>
. Why is that so? And how could i accomplish this otherwise?