【发布时间】:2019-12-16 08:06:37
【问题描述】:
我有一个管道,它根据来自数据 json 的值返回一个 css 字符串。
主要组件
this.coords.push(new L.Marker([i.lat, i.lng], {
rotationAngle: i.heading,
rotationOrigin: 'bottom center',
icon: new L.DivIcon({
html: `<div style="width: 65px;";>
<img src="assets/icon/airplan.jpg" style="width: 20px;height: 25px;" ngClass='${i.heading}| heading'/>
</div>`
})
}).addTo(this.map)
问题是当我运行我的项目时,我只得到相同的管道名称输出,我的意思是看起来管道不起作用! 输出
<img src="assets/icon/airplan.jpg" style="width: 20px;height: 25px;" ngclass="272|heading">
有什么建议
【问题讨论】:
-
如果它在 TS 中,为什么不直接使用函数而不是管道?类似
<img src="assets/icon/airplan.jpg" style="width: 20px;height: 25px;" ngClass='"+this.calcHeading(i.heading)+"'/> -
因为标题的值是数字,而且你知道 css 不是像
.12{}这样的接受数字 -
这能回答你的问题吗? Is it possible to use a pipe in the code?
-
This 也很有帮助。
-
也许还发布管道的代码,因为您说它返回 css,在这种情况下考虑使用
[ngStyle]。另请注意,[ngClass]和[ngStyle]期望将对象作为值。喜欢[ngStyle]="{'width': someVar}"