I am using METRONIC 8 DEMO 2 (SAAS application) theme. I have created a new service and added an HTTP method to call the APIs. When subscribing to the API response in component.ts inside ngOnInit, I am not getting the exact behavior like angular.
Expected Behaviour:
When subscribing the data in the ngOnInit method, and using that data in (select component) component.html, it should show immediately after getting the response from the API in HTML
Actual Behaviour:
It's not showing any data and when changing the page route, it's showing the data.
The same, I tried in stackblitz, and I am getting the expected behavior, but not in this theme.
For more information you can take a look at the code here: https://stackoverflow.com/questions/73891667/select-option-is-not-loading-data-from-api-response-for-the-first-time
Good evening, could you tell me how to solve this problem?
Hi,
Try to dive into the topic of ChangeDetection in Angular: https://www.digitalocean.com/community/tutorials/angular-change-detection-strategy.
Once you have a response from the server, try to detect changes like it's mentioned in the article.
Regards,
Keenthemes support
Thanks, @Carmelo. But is it not a default behaviour of the angular to detect the changes in the application? I am trying to find the place where the change detection has been detached. Can you help me remove this change detection as this can lead to the manual triggering of the change detection which is not good practice for the larger application?
Help me add the change detection for all the components in the project.
Hi,
You can setup ChangeDetectionStrategy.Default
instead of ChangeDetectionStrategy.OnPush
(check in all project files). But we don't recommend (but we can't restrict) doing this, cause it can worsen the application's performance.
Regards,
Keenthemes support