特定条件的ngstyle
<h4 *ngFor="let x of textAddedList"
[ngStyle]="{backgroundColor:textAddedList.length>2?'grey':'transparent'}">
{{x}}
</h4>
我只想在两个条目后才应用灰色样式,但是当我应用此逻辑时,它适用于第二行之后。提前致谢。
<h4 *ngFor="let x of textAddedList"
[ngStyle]="{backgroundColor:textAddedList.length>2?'grey':'transparent'}">
{{x}}
</h4>
I want to apply the grey styling only after the 2 entries, but when I apply this logic it applies to all instead after 2nd line. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
index
在*ngfor
中使用。由于数组的索引始于0,对于第二行之后的行,索引大于1:示例stackblitz demo
Work with
index
in*ngFor
. As the index of array starts with 0, for the rows after the second row, the index are greater than 1:Sample StackBlitz Demo