简体   繁体   English

无法绑定到'ngSwitchDefault',因为它不是'ng-template'的已知属性

[英]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' 无法绑定到'ngSwitchDefault',因为它不是'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'." 在我继续之前:这不是 Angular2的重复- “无法绑定到'ngSwitchWhen',因为它不是'模板'的已知属性。”

The ngSwitchWhen binds perfectly nice just the way that I used it. ngSwitchWhen绑定非常好,就像我使用它的方式一样。 The problem is with the ngSwitchDefault, which I can only use in it's sytactic suggared verison *ngSwitchDefault . 问题在于ngSwitchDefault,我只能使用它的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. 但由于我对此事有另一个结构性指令( * ngIf ),我想使用“Template- [ngSwitchDefault]” - Version,它给出了上述错误。

Question: Any reason why I can use [ngSwitchCase], but not [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>

I think it should just be 我认为它应该是

<ng-template ngSwitchDefault>

because ngSwitchDefault doesn't get a value passed and doesn't have an @Input() 因为ngSwitchDefault没有传递值并且没有@Input()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NG2-Charts模板解析错误:无法绑定到“数据集”,因为它不是“ canvas”的已知属性 - NG2-Charts Template parse errors: Can't bind to 'datasets' since it isn't a known property of 'canvas' NG2-Charts 无法绑定到“数据集”,因为它不是“画布”的已知属性 - NG2-Charts Can't bind to 'datasets' since it isn't a known property of 'canvas' NG0303:无法绑定到“ngif”,因为它不是“div”的已知属性 - NG0303: Can't bind to 'ngif' since it isn't a known property of 'div' 具有Angular 4的ng2-chart:无法绑定到“数据”,因为它不是“ canvas”的已知属性 - ng2-chart with Angular 4: Can't bind to 'data' since it isn't a known property of 'canvas' NG0303:无法绑定到“ngbTooltip”,因为它不是“button”的已知属性 - NG0303: Can't bind to 'ngbTooltip' since it isn't a known property of 'button' 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) 无法绑定到“ useStickyClasses”,因为它不是“ div”的已知属性 - Can't bind to 'useStickyClasses' since it isn't a known property of 'div' Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“ngModel”,因为它不是“输入”的已知属性 - Can't bind to 'ngModel' since it isn't a known property of 'input' 无法绑定到“matMenuTrigger”,因为它不是“a”的已知属性 - Can't bind to 'matMenuTrigger' since it isn't a known property of 'a'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM