Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Angular is not working as expected in theme. [select data are not working]


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


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


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



Good evening, could you tell me how to solve this problem?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(