Reputation: 83
Is it possible to use KeyValuePipe not in html but in ts file? If yes, could someone show me how?
This is what I have now but obviously I cannot use the pipe like this.
let item of this.entityDetails | keyvalue{
let properties:PropertyBase<any>[]=[
new TextboxProperty({
key: item.key,
label: item.key,
value: item.value,
required: false,
}),
];
}
Big thanks in advance
Upvotes: 0
Views: 1157
Reputation: 837
yes You Can use pipe in ts file.
constructor(public dataformatpipe: DateFormatPipe){}
ngOnInt(){}
formatData(date) {
return this.dataformatpipe.transform(date);
}
html file
<span class="value-data">{{formatData(item.startData)}}</span>
Upvotes: 0
Reputation: 2682
Sure you can. You just have to import it and inject it like any service. You import it from @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
})
];
}
}
Upvotes: 2
Reputation: 382
Write a custom pipe there you can write in ts file so you can transform , pass from parent as pipe input and work with your pipe ts file for refernce go here https://alligator.io/angular/custom-pipes-angular/
Upvotes: 0