[英]How can i check the value of let i = index in ngIf directive
I have a for loop.我有一个 for 循环。
<div *ngFor="let product of products;let i =index">
<div *ngIf="'i' != 3>
</div>
</div>
I am checking the value of i in my ngIf,so to show or to now show something.我正在检查我的 ngIf 中 i 的值,以便显示或现在显示某些内容。 But it does not work.I have a third index in my products array but it does not work.但它不起作用。我的产品数组中有第三个索引,但它不起作用。 Where is my mistake?我的错误在哪里?
I tried also我也试过
<div *ngIf="i != 3">
</div>
But without success但没有成功
You dont have to put 'i' in string conotations in the *ngIf directive.您不必在 *ngIf 指令中将 'i' 放在字符串含义中。
also you should use double equals : !== and not != .你也应该使用双等号: !==而不是!= 。
<div *ngFor="let product of products;let i =index">
<div *ngIf="i !== 3">
</div>
</div>
EDIT: Also you should consider using <ng-container>
for such procedures, to have a clear sepearation of concerns for semantics.编辑:您还应该考虑将<ng-container>
用于此类程序,以明确区分语义问题。
<ng-container *ngFor="let product of products;let i =index">
<div *ngIf="i !== 3">
this is product {{i}}
</div>
</ng-container>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.