[SOLUCIÓN] Can’t have multiple template bindings on one element. Use only one attribute prefixed with *

Can’t have multiple template bindings… Es muy común encontrar este tipo de errores cuando estamos empezando en el mundillo de ANGULAR, para fortuna de todos es fácil solucionarlo.

Esto ocurre porque estamos usando dos directivas con prefijo * en una misma etiqueta, por ejemplo:

<div *ngIf="item.selected" *ngFor="let item of list" > </div>
Can't have multiple template bindings on one element. Use only one attribute prefixed with *

Como podemos notar usamos *ngIf y *ngFor para solucionarlo debemos agregar la condición a un nivel inferior en el árbol HTML, así:

<div *ngFor="let asesor of asesores" >
  <h1 *ngIf="asesor.selected" > {{ asesor.name }} </h1>
</div>
Can't have multiple template bindings on one element. Use only one attribute prefixed with *

No necesariamente tienes que usar <h1>, simplemente es para temas didácticos, eso dependerá de vuestras necesidades.

Puedes hecharle un vistazo a la documentación oficial de la directiva ngIf aquí.

7 respuestas a «[SOLUCIÓN] Can’t have multiple template bindings on one element. Use only one attribute prefixed with *»

  1. Hi there! I know this is somewhat off topic but I was wondering which blog platform are you
    using for this website? I’m getting sick and tired of WordPress
    because I’ve had issues with hackers and I’m looking at alternatives for another platform.
    I would be great if you could point me in the direction of a good platform.

  2. May I simply just say what a relief to find someone who truly understands what they are discussing on the web. You definitely understand how to bring a problem to light and make it important. More and more people ought to check this out and understand this side of your story. Its surprising you arent more popular because you definitely have the gift.

Deja una respuesta

Tu dirección de correo electrónico no será publicada.