How to use a direct Html tag on my object?

Asked

Viewed 39 times

-1

Example, I want to make a list with the HTML tag

<ul>
  <li>primeiro item</li>
  <li>segundo item</li>
  <li>terceiro item</li>
</ul>

And my object is like this

teste = {nome: "primeiro item segundo item terceiro item"}
  • Your question is unclear, you can explain it better?

  • and what have you tried to do? have you seen the questions here on the site with similar ideas, such as this:ngFor ?

  • Eduardo Vargas, is my object right? test = {name: "first item second item third item"} I want to do this within the test object = {name: "<ul><li>first </li> <li><li>second item</li><li> third item</li>"} and this object automatically already formats and gets a list. I could understand brother?

1 answer

0


First you have to separate your string into an array of substrings based on something. For example by spaces:

meuArray:string[]

ngOnInit(){
teste = {nome: "primeiro item segundo item terceiro item"}
this.meuArray= teste.nome.split(' ');
}

And then only use ngFor in your array

<ul>
  <li *ngFor"let item of meuArray">{{item}}</li>
</ul>
  • Thanks friend, I will try here. Hugs and thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.