0

I would like to insert a text using the dir=auto directive and either read the same text that I insert into the database, or reuse the same dir=auto directive to display the text correctly.

I insert text into db using textarea and dir directive to detect direction automatically :

<textarea dir="auto" [(ngModel)]="Text"></textarea>

After loading from db, in ngOnInit() ts component i use bypassSecurityTrustHtml to get html :

Text = this.sanitizer.bypassSecurityTrustHtml(Text) as string;

Then i try to display it in html but text dosen't displayed same when inserted at first :

<p dir="auto" [innerHTML]="Text"></p>

After loading from db is always left to right

Any idea please.

itdev
  • 43
  • 1
  • 6
  • what's the difference in text you are seeing after loading from db? – Sikander Oct 16 '22 at 00:46
  • check this https://stackoverflow.com/questions/39857858/angular-2-domsanitizer-bypasssecuritytrusthtml-svg – Sikander Oct 16 '22 at 00:50
  • @Sikander when writing in textarea the direction is auto depending of caracters, but after loading from db is always left to right – itdev Oct 16 '22 at 11:15
  • @Sikander according my checks i think dir="auto" works for each paragraph using textarea then we see text formated correctly (example line with frensh caracters begins from left to right, and second paragraph of arabic caracters begins from right to left), but when we want to load this text from dababase or directly and print using

    the problem is dir="auto" will work for all text not for each paragraph, it's my remark, then solution i think is two split hole text into paragraphs and add style into each one

    – itdev Oct 16 '22 at 15:14

0 Answers0