gpt4 book ai didi

Angular : Using pipe inside ts not in html

转载 作者:行者123 更新时间:2023-12-02 17:16:58 27 4
gpt4 key购买 nike

我有一个管道,它根据来自 data 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">

有什么想法请提出来

最佳答案

您是否尝试过使用不带 ${} 括号的 ngClass

[ngClass]='i.heading | heading'

否则,您可以在组件类中运行管道:

您可以将管道注入(inject)构造函数并运行转换函数

@Component({...})
export class MyComponent {
constructor(private headingPipe: HeadingPipe) {}

transformedHeading(heading: string) {
return this.headingPipe.transform(heading);
}
}

并在您的模板中

<img [ngClass]="transformedHeading(i.heading)"/>

关于 Angular : Using pipe inside ts not in html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59352591/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com