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

1

11

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>
Rifle answered 4/9, 2017 at 12:33 Comment(0)
E
20

I think it should just be

<ng-template ngSwitchDefault>

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

Evocative answered 4/9, 2017 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.