I am trying to use ngOnChanges to create a search filter as the user types in letters into the input. Here is my code:
export class SearchComponent implements OnInit, OnChanges {
@Input() search:string
// trying to get this to run each time the input value changes
public ngOnChanges(changes: any) {
console.log(changes.search);
}
}
@NgModule({
imports: [MaterialModule, FlexLayoutModule, BrowserModule, FormsModule]
// declarations, providers, exports also defined here
})
Input element in the component template:
// using Material Design Library
<input mdInput [search]="searchText" type="text" placeholder="Search"></input>
Or can I only use an @Input like this:
<search-component [search]="searchText"></searchComponent>
But then does searchText here bind to my controller?
The error I keep getting is "Can't bind to "search" since it isn't a know property of "input".
I had the understanding that the @Input decorator took care of that but clearly I am missing something here.
Note: I did add the filter using (ngModelChange) and binding to the [(ngModel)] value in my controller..works fine. But it sounds like using ngOnChanges is the best way to do this so I'm trying to understand how to make it work. Thanks