Can't bind to 'ngSwitchDefault' since it isn't a known property of 'ng-template'

8.5k views Asked by At

I get the error:

Can't bind to 'ngSwitchDefault' since it isn't a known property of 'ng-template'

Before I go on: this is not a duplicate of Angular2 - "Can't bind to 'ngSwitchWhen' since it isn't a known property of 'template'."

The ngSwitchWhen binds perfectly nice just the way that I used it. The problem is with the ngSwitchDefault, which I can only use in it's sytactic suggared verison *ngSwitchDefault. But since I have another structural directive on the matter (*ngIf) I would like to use the "Template-[ngSwitchDefault]"-Version, which gives me the aforementioned error.

Question: Any reason why I can use [ngSwitchCase], but not [ngSwitchDefault] ?

<div>
  <div *ngFor="let field of fields">
    <ng-container [ngSwitch]="field.myType">
      <ng-template [ngSwitchCase]="'something'">
        <div *ngIf="fieldIsVisibile[field.name]">
          Somthing special: {{field.name}}
        </div>
      </ng-template>

      <ng-template [ngSwitchDefault]>
        <div *ngIf="fieldIsVisibile[field.name]">
          Regular: {{field.name}}
        </div>
      </ng-template>
    </ng-container>
  </div>
</div>
1

There are 1 answers

0
Günter Zöchbauer On BEST ANSWER

I think it should just be

<ng-template ngSwitchDefault>

because ngSwitchDefault doesn't get a value passed and doesn't have an @Input()