2
我得到的錯誤:不能綁定到「ngSwitchDefault」,因爲它不是「NG-模板」的已知財產
Can't bind to 'ngSwitchDefault' since it isn't a known property of 'ng-template'
我去之前:這是不一Angular2 - "Can't bind to 'ngSwitchWhen' since it isn't a known property of 'template'."
ngSwitchWhen綁定非常好,就像我使用它的方式。問題出在ngSwitchDefault上,我只能使用它的sytactic suggared verison * ngSwitchDefault。但由於我對此事有另一個結構指示(* ngIf),我想使用「Template- [ngSwitchDefault]」 - 版本,它給了我上述錯誤。
問題:爲什麼我可以使用[ngSwitchCase],但不是[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>