Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
Which is a better way to access a large object's data members?

I have an object in my .ts file consisting of dozen of data members. Now, in order to render them in my html at different places for all different members, shall I reference it from the object directly -

.html

<p>{{obj.m1}}</p>
<p>{{obj.m2}}</p>

OR, I define each variable in .ts file differently - .ts

m1 : string = obj.m1;
m2 : string = obj.m2;

.html

<p>{{m1}}</p>
<p>{{m2}}</p>

I am not sure if it does make a difference.

Thank You!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's perfectly fine to reference an object property (and its members) of a component from a template.

In order to do that, object property must be public (the default).

Good practice could be also to use Safe navigation operator (?) to avoid any null or undefined value in object member.

<p>The item name is: {{item?.name}}</p>

If item is null, the view still renders but the displayed value is blank; you see only "The item name is:" with nothing after it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda