I successfully accessed this route:
http://localhost:8100/questions/question?id=3
However, I am facing a challenge in handling two subscribers simultaneously.
The first subscriber is responsible for loading the questions array from an external service.
The second subscriber is tasked with retrieving the desired Question
object based on the route parameter.
app_data:AppData;
question:Question;
ngOnInit() {
this.appService.app_data.subscribe((v) => { this.app_data = v; });
this.route.queryParams.subscribe(p => {
this.question = this.appService.app_data.questions.find(i => i.id === params.id);
});
}
The issue arises when I navigate to this route as it attempts to filter the array before it is fully loaded by the service.
ERROR TypeError: Cannot read properties of undefined (reading 'find')
Is there a mistake in my approach?