-1

    <ng-container *ngIf="selectedPlayer; else infoText">
      <div *ngFor="let playerEL of players">
          [playersTEST]="playerEL"
          (playerWasSelected)="onPlayerSelected(playerEL)">
      </div>

    </ng-container>

  </app-stats>

What is the correct way of doing this?

3 Answers3

3

Little Typo in your code. You need to reformat your DIV code correctly as given below

<div *ngFor="let playerEL of players"
          [playersTEST]="playerEL"
          (playerWasSelected)="onPlayerSelected(playerEL)">
      </div>

and then implement your IF ELSE as suggested by @windmaomao.

Swanand Taware
  • 723
  • 2
  • 7
  • 32
2

They do have some conflicts in Angular2+. Angular2 doesn't support more than one structural directive on the same element. So you can split them into two elements.

<ng-container *ngIf="selectedPlayer else infoText">
    <div *ngFor="let playerEL of players"></div>
</ng-container>
<ng-container #infoText>
    No records.
</ng-container>

ng-container can avoid create extra div, otherwise you can use ng-template.

windmaomao
  • 7,120
  • 2
  • 32
  • 36
-1

It looks like your directive hadn't been instantiated or recognized. Check the directive selector or if you add it in the module, or if you add the directive's module to the component module.

OPulido
  • 309
  • 2
  • 10