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

dynamic switching between rtl css and ltr scc - Angular - Metronic 8


Hello, I was trying to switch between RTL to LTR with Angular and I have implemented this way


document.querySelector("link[href='styles.css']")?.setAttribute('id', 'main-layout');
this.translationService.updateLangLayout();

updateLangLayout(lang? : string){
if(lang){
if (lang == 'ar') {
document.getElementById("main-layout")?.setAttribute('href', location.origin + "/assets/sass/style.bundle.rtl.css");
document.querySelector('html')?.setAttribute('dir', 'rtl');
document.querySelector('html')?.setAttribute('direction', 'rtl');
} else {
document.getElementById("main-layout")?.setAttribute('href', location.origin + "/styles.css");
document.querySelector('html')?.setAttribute('dir', 'ltr');
document.querySelector('html')?.setAttribute('direction', 'ltr');
}
}
else{
if (this.getSelectedLanguage() == 'ar') {
document.getElementById("main-layout")?.setAttribute('href', location.origin + "/assets/sass/style.bundle.rtl.css");
document.querySelector('html')?.setAttribute('dir', 'rtl');
document.querySelector('html')?.setAttribute('direction', 'rtl');
} else {
document.getElementById("main-layout")?.setAttribute('href', location.origin + "/styles.css");
document.querySelector('html')?.setAttribute('dir', 'ltr');
document.querySelector('html')?.setAttribute('direction', 'ltr');
}
}
}

I added this code inside the ngOnInit function and inside App.component.ts.

It works fine locally but when I deployed it It did not work because the id attr is not 'main-layout', which means this code does not work
document.querySelector("link[href='styles.css']")?.setAttribute('id', 'main-layout');


what is the solution?


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,

Hard to help you with your custom code, cause we aren't able to reproduce it.
Anyway, if you need a custom 'ID' attr, just try to add this 'ID'.

Regards,
Keenthemes support


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