<tr *ngFor="let logDetails of logDetails | search : term" >
I have a Pipe in which I want to use a variable. Same variable has been defined in my Component. How can I pass this value from Component to Pipe?
//Pipe Structure
transform(value, [term], newVal) {
if (value == undefined && newVal == undefined) {
return undefined;
} else {
return value.filter((item) => item.LogString.startsWith(term));
}
}
//Component Structure
newVal(a) {
this.newChildData = a;
console.log(this.newChildData);
}
I want to pass newChildData
of Component into newVal
of Pipe.
// HTML Template
It's either you use the pipe in the template and pass new value into it.
Or, since Pipe is just a Javascript class, you can import it in your component and use it.
But I won't suggest the later.
If you want to use the pipe programmatically, consider splitting the transform logic to service, then import and use that service in both
pipe
andcomponent
.