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

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • 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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(