Setting new direction not working after any reload!


#1

Hello guys. I have a project that made in Ionic. It is supporting ‘LTR’ language. And ‘RTL’ language. I wrote this code to handle the selected language in languages.ts file:

if(this.form.value.lang == 'ar')
    {
      this.plt.setDir('rtl',true);
      
      setTimeout(() => {
        window.location.reload();
      }, 100);
    }
    else if(this.form.value.lang == 'en')
    {
      // this.plt.setDir('ltr',true);
    setTimeout(() => {
      window.location.reload();
    }, 1200);
    }

$app-direction is multi
and default dir in index.html is LTR

So, the above code will change the app direction to RTL or LTR.
But when the app reload the direction back to LTR!!.
Help me please! I really tired!


#3

Your code doesn’t seem consistent with the official documentation. If you follow the official Ionic code samples, you’ll probably get better results. Also, as a general comment about JS programming: if you use setTimeout, you’ve almost always made a mistake.