Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display html element from JSON object on ionic App

I have been trying to embed html element from JSON object, and It is currently displaying the html as raw code instead.

Can someone please help me ?

detail.ts

 this.questionsData[i].question_type.title = "<ion-input type=\"text\" placeholder=\"Short answer\"></ion-input>";

detail.html

<ion-item  *ngFor="let question of questionsData">
      {{question.title}}
      <br>
      Text : {{question.question_type.title}}
      <br>
     <div   [innerHTML]="question.question_type.title">
    </div>
</ion-item>

example

Isn't it should be input box under the text : , anyone know why it's not rendered ?

Thanks

like image 416
damniatx Avatar asked May 26 '26 15:05

damniatx


1 Answers

InnerHtml will only help to render pure html code on run time, you can't use ionic components to render dynamically using innerhtml. I think you need to use dynamic component loader feature in angular here. You can refer this link on use cases of this feature https://medium.com/@DenysVuika/dynamic-content-in-angular-2-3c85023d9c36

like image 192
Sathyajith Avatar answered May 30 '26 15:05

Sathyajith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!