【问题标题】:ternary operator on shape attribute doesn't work形状属性的三元运算符不起作用
【发布时间】:2018-12-05 11:35:04
【问题描述】:

我正在尝试向shape 添加三元条件,这是一个图标类型shape="success-standard" - 在shape="name.active ? 'success-standard' : 'times-circle'" 中,我正在尝试为图标类型添加条件。并且使用 [shape] 指令不起作用

<clr-dg-row class="man-rcs" *ngFor="let name of visibleNames">
  <clr-dg-cell (click)="handleRowClick(name)" class="tac">
    <clr-icon size="18" shape="name.active ? 'success-standard' : 'times-circle'">
    </clr-icon>
  </clr-dg-cell>
</clr-dg-row>
通常我会这样做,但在这种情况下,这不是我想要的
<clr-dg-cell class="tac">
  <clr-icon size="18" *ngIf="name?.active" shape="success-standard" class="is-solid is-success"></clr-icon>
  <clr-icon size="18" *ngIf="!name?.active" shape="times-circle" class="is-solid is-danger"></clr-icon>
</clr-dg-cell>

【问题讨论】:

    标签: html angular6 vmware-clarity


    【解决方案1】:

    你需要像这样绑定到 shape 属性。图标是我们的 Web 组件,因此您必须使用这种不同的方法。

    [attr.shape]=“name.active ? ‘success-standard’ : ‘times-circle’”

    详情请见How can I dynamically change the shape of a clr-icon custom element?

    【讨论】:

      【解决方案2】:

      试试下面的代码

      <clr-icon size="18" shape="{{name.active == true ? 'success-standard' : 'times-circle'}}">
      

      或者

      <clr-icon size="18" shape="(name?.active == true ? 'success-standard' : 'times-circle')">
      

      希望第一个代码能正常工作

      【讨论】:

      • 两者都不起作用错误消息`-不能绑定到'shape',因为它不是'clr-icon'的已知属性。 1. 如果'clr-icon'是一个Angular组件并且它有'shape'输入,那么验证它是这个模块的一部分。
      猜你喜欢
      • 2016-03-30
      • 2019-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-30
      • 2018-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多