I would like to display data in Angular 7/8 based on user search parameters. Initially the view should be blank,but when the user inputs the search parameters and clicks the Submit button the view should be updated with the new/filtered information.
Desired approach: Empty ArrayB should be populated with the filtered data of ArrayA
Implementation:
ArrayA = [{id:1, Name:"Steve"},{id:2, Name:"Maureen"},{id:3, Name:"Damian"},{id:4, Name:"Dee"}];
ArrayB = [];
HTML code:
<div class="container">
<div class="row">
<form class="form" [formGroup]="filterForm" >
<label for="">ID</label>
<input type="text" name="person_id" formControlName="person_id" id="person_id">
<button type="submit" (click)="submit($event)">Submit</button>
</form>
</div>
<div class="row">
<div class="col-12" ngFor="let filteredArr of ArrayB">{{filteredArr.name}}</div>
</div>
</div>
When i click submit, the ArrayA should be filtered based on the ID provided by the user and pushed into ArrayB and the view updated with the new information.
submit(event){
//Filter ArrayA and push to ArrayB
}
If there is a better and much simpler way of achieving the same i will greatly appreciate