【发布时间】:2019-01-01 01:33:36
【问题描述】:
有没有办法通过 HTML 将元素作为属性发送?例如:
在 HTML 中:
<ul>
<li *ngFor="let item of items">
<my-component [ngClass]="{'whatever': checkElement(my-component)}">
</li>
</ul>
在ts文件中:
checkElement(el): boolean {
// dummy code
const size = el.getBoundingClientRect();
return size.bottom > 100;
}
我知道有几种方法可以获取该元素,但这将在一个巨大的循环中使用,我想防止在 DOM 中搜索该元素(如果可能的话)。
谢谢!
【问题讨论】: