Search code examples
angularangular7angular-filtersangular-template

Error: Template parse errors: The pipe 'filter' could not be found in angular


imported this filter

// search module
import { Ng2SearchPipeModule } from 'ng2-search-filter';

HTML code for it

//search

<input class="form-control" type="text" name="search" [(ngModel)]="searchText" autocomplete="off" placeholder="search">

//Assigned filter to table

 <tr *ngFor="let bookName of NameOfBookList | filter:searchText">

Any help would be appreciated.


Solution

  • Adding Ng2SearchPipeModule ONLY to the imports worked for me. When adding to the declarations I got an error in my browser tools stating that there was an unexpected delcaration for Ng2SearchPipeModule.

    @NgModule({
    declarations: [
        AppComponent,
        ListComponent
    ],
    imports: [
        BrowserModule,
        FormsModule,
        Ng2SearchPipeModule
    ],
    providers: [],
    bootstrap: [AppComponent]
    })
    

    Then in my markup:

    <input [(ngModel)]="term">
    ...
    <tbody *ngFor="let d of myList |filter:term">