I am looking to customize the user.component template by implementing a filter functionality that will display only the users in the array that match the string entered in the text input field. Is there a way to bind the input value to the view without relying on a custom pipe since using the 'filter' pipe is no longer an option in Angular 6?
If I opt for [(ngModel)] two-way binding directive, how can I filter the string passed into it within my component without requiring a custom pipe?
Below is the users.component.html template:
<div class="wrapper">
<span id = "search-box"><input class = "col-lg-7" id= "search-input" type="text" name="users" placeholder = "Search by name"></span>
<span id= "people">{{users.length}} <span *ngIf = "users.length == 1">Person</span><span *ngIf = "users.length > 1">People</span></span>
<div class="accordion" id="accordionExample">
<div class="card" *ngFor = "let user of users">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" type="button" data-toggle="collapse" [attr.data-target]="'#' + user" aria-expanded="true" aria-controls="collapseOne">
{{user}}
</button>
</h5>
</div>
<div [attr.id]= "user" class="collapse" aria-labelledby="headingOne" data-parent="#accordionExample">
<div class="card-body">
<img src="./assets/user.jpg" id= "user-pic">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div><!-- end of .card -->
</div><!--end of .accordion-->
</div><!--end of .wrapper -->
And here is the users.component.ts file:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.css']
})
export class UsersComponent implements OnInit {
users: any[] = [
"Bob",
"James",
"Mary"
];
constructor() { }
ngOnInit() {
}
}
If utilizing a custom pipe becomes necessary, please provide instructions on setting this up.