Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda