Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

KTUI stops responding after a route change in angular


I've taken Metronic 9.2, and converted it to angular sucessfully with demo 1.

When I initially launch Metronic it appears to work, but after a route change KTUI stops working after a route is changed.

I have tried to initiatlise KtUi manually like this in the app.component :

constructor() {
this.router.events.pipe(filter(e => e instanceof NavigationEnd)).subscribe(() => {
this.updateDemo();
// Delay initialization to ensure view is rendered
setTimeout(() => {
this.metronicInitService.init();
}, 0);
});
this.updateDemo();
}

It works again if I refresh the page using the refresh option via the browser.


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 (1)


Hi

Use requestAnimationFrame instead of setTimeout for better timing:

constructor() {
this.router.events.pipe(
filter(e => e instanceof NavigationEnd),
// Unsubscribe to prevent memory leaks
takeUntil(this.destroy$)
).subscribe(() => {
this.updateDemo();
// Use requestAnimationFrame for better timing
requestAnimationFrame(() => {
requestAnimationFrame(() => {
this.metronicInitService.init();
});
});
});
this.updateDemo();
}


Or use a longer delay with setTimeout:

setTimeout(() => {
this.metronicInitService.init();
}, 100); // Increase delay to 100ms


Thanks


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  :(