3 回答
![?](http://img1.sycdn.imooc.com/5f33c0c90001f9ad05720572-100-100.jpg)
TA贡献1155条经验 获得超0个赞
你当然可以。你只需要像任何服务一样导入它并注入它。你从@angular/common.
import { KeyValuePipe } from "@angular/common";
constructor(private keyValuePipe: KeyValuePipe) {
const transformed = this.keyValuePipe.transform(this.entityDetails);
for (let item of transformed) {
let properties: PropertyBase<any>[] = [
new TextboxProperty({
key: item.key,
label: item.key,
value: item.value,
required: false
})
];
}
}
![?](http://img1.sycdn.imooc.com/533e4c640001354402000200-100-100.jpg)
TA贡献1864条经验 获得超2个赞
是的,您可以在 ts 文件中使用管道。
constructor(public dataformatpipe: DateFormatPipe){}
ngOnInt(){}
formatData(date) {
return this.dataformatpipe.transform(date);
}
html文件
<span class="value-data">{{formatData(item.startData)}}</span>
![?](http://img1.sycdn.imooc.com/533e4ce900010ae802000200-100-100.jpg)
TA贡献1887条经验 获得超5个赞
在那里编写一个自定义管道,您可以在 ts 文件中写入,以便您可以转换,从父级作为管道输入传递并使用您的管道 ts 文件以供参考,请访问此处 https://alligator.io/angular/custom-pipes-angular/
添加回答
举报