【问题标题】:replace for an interpolation in angular inputs [duplicate]替换角度输入中的插值[重复]
【发布时间】:2020-05-15 13:46:15
【问题描述】:

我正在遍历一个数组并每次显示一个角度分量。

<div *ngFor="let category of categories; let i=index" id="category_{{i}}">
 <app-category
          [inputId]="'category_'[i]"
  </app-category>
</div>

类别组件是递归的,我需要发送这个 inputId 并将其用作 html id 像这样

id="{{inputId}}_{{i}}"

app-cateogry.html

<!--Some html -->
    <div *ngFor="let subCategory of subCategories; let i=index" id="subCategory_{{i}}">
     <app-category
              [inputId]="'category_'[i]"
      </app-category>
    </div>

问题是我无法像上面尝试的那样发送索引。 我也尝试过插值([inputId]="'category_'{{i}}"),但这不适用于输入

我想要实现的是在子类别组件上有一个像“category_categoryIndex_subCategory_subCategoryIndex”这样的ID

【问题讨论】:

  • inputId="category_{{i}}"
  • 你会在this post找到答案。

标签: angular


【解决方案1】:

你可以如下使用:

[inputId]="{{'category_'+ i}}"

【讨论】:

    【解决方案2】:

    这是解决方案[inputId]="'category_'+i";您不能对输入使用插值,因此我将字符串“类别”与索引连接起来

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-19
      • 2018-02-15
      • 2019-11-24
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 2019-01-23
      相关资源
      最近更新 更多