HTML displaying from MySQL


#1

Hi.

I have a MySQL database connected to my App. When I display the content, I want :

  • to transform URL in text in order to click on. (For now, the URL displayed is just text)
  • to display carriage return

I tried to use “DomSanitizer” from Angular, but no success (may be I read the docs wrong)
What must I do ?

That’s my HTML code

<div id="msgOrigine">
                <p>{{item.auteur}}</p>
                <h3 style="margin: 0; padding-bottom: 0.5em">{{item.titre}}</h3>
                {{item.contenu}}
</div>

And that’s my TS :

load() : void
   {
      this.http
      .get('http://localhost:8888/recup-reponses-sujet.php?idSujet='+String(this.item.id))
      .subscribe((data : any) =>
      {
         console.dir(data);
         this.itemsBDD = data;
      },
      (error : any) =>
      {
         console.dir(error);
      });
   }

urlIonic

Thank you for your help :slight_smile:


#2

Somebody will probably come in and recommend innerHTML. I would instead suggest pretending that doesn’t exist, and looking at a solution along the lines of this instead.