Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 953
Tobias Gassmann Avatar asked Sep 04 '17 12:09

Tobias Gassmann


1 Answers

I think it should just be

<ng-template ngSwitchDefault>

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

like image 123
Günter Zöchbauer Avatar answered Oct 18 '22 04:10

Günter Zöchbauer