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

118
Visualizações
Return multiple values from a function in Angular and use those values inside HTML div tag. The return values can't be assigned to variable in TS file

I have a function which returns a string, a css class and a boolean like this [false, green_box]. I want to utilise this values in below HTML but unfortunately I am unable to do so. How can I access the values? Since the function is called multiple times inside the HTML file I cannot assign the return values in a variable in typescript file.

Please note that I can use different function to return boolean value but the goal is to find a way to utilize multiple values returned from a function in HTML.

Below is my HTML

<div *ngIf="getClass('investing', 'plan')[0]"
     class="prio_box dnd_move"
     data-drag="list-1"
     data-drag-index="0">

  <span [ngClass]="getClass('investing', 'plan')[1]" 
      class="dnd_move clr-box">
  </span>

  <span class="drag_content dnd_move">Plan</span>

</div>

Here is my function,

getClass(component: string, value: any) {
    component = component.toLowerCase();
    value = value.replace(/\s/g, "");
    let pathValue = this.control[component]
      ? this.control[component.toLowerCase()][value]
      : null;
    this.allGreen.add(pathValue);
    return [pathValue == Status.Yes
      ? "green_box"
      : pathValue == Status.DontKnow
      ? "yellow_box"
      : "red_box",
      pathValue == Status.Yes
      ? false
      : pathValue == Status.DontKnow
      ? true
      : true];

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

0

Try doing something like this:

<ng-container *ngIf="getClass('investing', 'plan') as class">
<div *ngIf="class[0]"
     class="prio_box dnd_move"
     data-drag="list-1"
     data-drag-index="0">

  <span class="dnd_move clr-box {{class[1] || ''}}">
  </span>

  <span class="drag_content dnd_move">Plan</span>

</div>
</ng-container>

Using this way, you can prevent function from being called multiple times.

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