简体   繁体   English

从 ngFor 到动态命名变量的角度引用 ngIf

[英]Angular reference ngIf to dynamic namined variable from ngFor

I want to access the input element in the following ngIf for checking if it's currently having a specific value or not.我想访问以下 ngIf 中的输入元素,以检查它当前是否具有特定值。 The not working part here is the code inside the ngIf .这里不起作用的部分是ngIf的代码。

<span *ngFor="let item of items;let i=index">
      <input type="text" #[InputItem+i] value="{{item}}"/>
      <div *ngIf="('InputItem'+i).value" >
        I'm focused!
      </div>
</span>
<span *ngFor="let item of items;let i=index">
  <input type="text" value="{{item}}"/>
  <div *ngIf="InputItem[i]" >
    I'm focused!
  </div>

Declare variable InputItem:[] as array将变量 InputItem:[] 声明为数组

Try to declare InputItem as arry like InputItem[0] = false,InputItem[1] = false like wise and you can update the variable when you need based condition尝试将 InputItem 声明为 arry 像 InputItem[0] = false,InputItem[1] = false 一样明智,您可以在需要基于条件时更新变量

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM