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?
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