无法绑定到“ngSwitchDefault",因为它不是“ng-template"的已知属性 [英] Can't bind to 'ngSwitchDefault' since it isn't a known property of 'ng-template'

查看:63
本文介绍了无法绑定到“ngSwitchDefault",因为它不是“ng-template"的已知属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误:

<块引用>

无法绑定到ngSwitchDefault",因为它不是'ng-模板'

在我继续之前:这是不是Angular2 - 无法绑定到 'ngSwitchWhen',因为它不是 'template' 的已知属性."

ngSwitchWhen 绑定得非常好,就像我使用它的方式一样.问题在于 ngSwitchDefault,我只能在它的语法推荐版本 *ngSwitchDefault 中使用它.但由于我有另一个关于此事的结构指令 (*ngIf),我想使用Template-[ngSwitchDefault]"-Version,这给了我上述错误.

问题:为什么我可以使用 [ngSwitchCase] 而不能使用 [ngSwitchDefault] ?

<div *ngFor="let field of fields"><ng-container [ngSwitch]="field.myType"><ng-template [ngSwitchCase]="'something'"><div *ngIf="fieldIsVisibile[field.name]">一些特别的东西:{{field.name}}

</ng-模板><ng-template [ngSwitchDefault]><div *ngIf="fieldIsVisibile[field.name]">常规:{{field.name}}

</ng-模板></ng-容器>

解决方案

我觉得应该是

因为 ngSwitchDefault 没有得到传递的值并且没有 @Input()

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 think it should just be

<ng-template ngSwitchDefault>

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

这篇关于无法绑定到“ngSwitchDefault",因为它不是“ng-template"的已知属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆