最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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>

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>
Share Improve this question asked Sep 4, 2017 at 12:33 Tobias GassmannTobias Gassmann 11.8k18 gold badges61 silver badges96 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 20

I think it should just be

<ng-template ngSwitchDefault>

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论