I have Angular6 project. It has listing component and detail component. In listing component, I have a search box. When I search anything and based on that when redirecting to the detail page, I am assigning queryParams and when coming back I am preserving those queryParams. And it is working fine.
But again when I type anything in the search box, I want to update the URL with the updated search string that I have entered in the search box without reloading the page again, i.e... I want to keep the queryParams updated while changing the search-box input field.
listing.component.html
<div class="input-group">
<input type="text" name="search" [(ngModel)]="search">
</div>
<div class="row" *ngFor="let List of Lists | searchFilter:search:'name' | paginate: { itemsPerPage: 25, currentPage: page }">
<div (click)="editList(List.ListId)">{{List.name}}</div>
</div>
listing.component.ts
ngOnInit(): void {
this.search = this.activatedRoute.snapshot.queryParams['search'] || '';
}
editPrice(ListId: number): void {
this.router.navigate(['lists/edit', ListId], { queryParams:
{ search: this.search }
});
}
detail.component.html
<a [routerLink]="['/lists']" queryParamsHandling="preserve">Go Back</a>