I'm trying to use a pipe to highlight certain text based on a dropdown selection in the app, I have the pipe module declared in app module, and registered as a provider for the component I want to use it in but I get an error saying can't find pipe with name. Below is the relevant code and how I'm trying to use it. Am I declaring the pipe incorrectly or registering incorrectly?
highlight-text.pipe.ts taken from https://stackoverflow.com/a/44962110/11881461
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'highlightText'
})
export class HighlightTextPipe implements PipeTransform {
transform(value: any, args: any): any {
if (!args) {return value;}
var re = new RegExp(args, 'gi'); //'gi' for case insensitive and can use 'g' if you want the search to be case sensitive.
return value.replace(re, "<mark>$&</mark>");
}
}
app.module.ts
@NgModule({
declarations: [
{other declarations},
HighlightTextPipe
],
page.component.ts
import {HighlightTextPipe} from '../../pipes/highlight-text.pipe';
@Component({
{other declarations}
providers: [HighlightTextPipe]
})
How I'm trying to use it in page.component.html:
<span>{{ text | highlightText : 'Annex'}}</span>
The error I am getting:
Error: src/app/components/page.component.html:89:69 - error NG8004: No pipe found with name 'highlightText'.
89 <span>{{text | highlightText : 'Annex'}}</span>