Last active
February 21, 2022 08:55
-
-
Save Mustafa-Omran/834b6066933ca72a9598e8c39eaf1694 to your computer and use it in GitHub Desktop.
Angular -custom directive for dynamic direction (rtl or ltr)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Directive({ | |
selector: '[setDirection]' | |
}) | |
export class SetDirDirective { | |
/** | |
* | |
* @param el | |
* @param languageService | |
* @param locale | |
*/ | |
constructor(private element: ElementRef, | |
private languageService: LanguageService, | |
) { | |
this.onChangeLanguage(); | |
} | |
onChangeLanguage() { | |
this.languageService.language.subscribe((languageCode:string) => { | |
switch (languageCode) { | |
case 'ar': | |
this.element.nativeElement.style.direction = 'rtl'; | |
this.element.nativeElement.style.textAlign = 'right'; | |
break; | |
default: | |
this.element.nativeElement.style.direction = 'ltr'; | |
this.element.nativeElement.style.textAlign = 'left'; | |
break; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment