xxxxxxxxxx
import { ActivatedRoute } from '@angular/router';
export class ExampleComponent implements OnInit {
constructor(private router: ActivatedRoute) { }
ngOnInit() {
this.router.queryParams.subscribe(res=>{
console.log(res) //will give query params as an object
})
}
}
xxxxxxxxxx
request(query) {
let params = new HttpParams().set("keyword", query);
return this.http.get(`Your_URL`, {params});
}
xxxxxxxxxx
navigateToFoo(){
this._router.navigate([], {
queryParams: {
newOrdNum: '123'
},
queryParamsHandling: 'merge',
});
}
xxxxxxxxxx
constructor(private router: Router) { }
public myMethodChangingQueryParams() {
const queryParams: Params = { myParam: 'myNewValue' };
this.router.navigate(
[],
{
relativeTo: activatedRoute,
queryParams: queryParams,
queryParamsHandling: 'merge', // remove to replace all query params by provided
});
}
xxxxxxxxxx
// Make sure to import and define the Angular Router and current Route in your constructor
constructor(
private router: Router,
private route: ActivatedRoute
) {}
// Take current queryParameters from the activated route snapshot
const urlParameters = Object.assign({}, this.route.snapshot.queryParams);
// Need to delete a parameter ?
delete urlParameters.parameterName;
// Need to add or updated a parameter ?
urlParameters.parameterName = newValue;
// Update the URL with the Angular Router with your new parameters
this.router.navigate([], { relativeTo: this.route, queryParams: urlParameters });
xxxxxxxxxx
export class HeroComponent implements OnInit {
constructor(private _activatedRoute: ActivatedRoute, private _router:Router) {
_router.routerState.queryParams.subscribe(
params => console.log('queryParams', params['st']));
xxxxxxxxxx
getFilteredPersonalBookmarks(searchText: string, limit: number, page: number, userId: string, include: string): Observable<Bookmark[]> {
const params = new HttpParams()
.set('q', searchText)
.set('page', page.toString())
.set('limit', limit.toString())
.set('include', include);
return this.httpClient.get<Bookmark[]>(`${this.personalBookmarksApiBaseUrl}/${userId}/bookmarks`,
{params: params})
.pipe(shareReplay(1));
}
xxxxxxxxxx
import { ActivatedRoute } from '@angular/router';
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-example',
template: '' // Your component template here
})
export class ExampleComponent implements OnInit {
constructor(private route: ActivatedRoute) { }
ngOnInit(): void {
this.route.queryParams.subscribe(params => {
// Access query parameters here
console.log('Query Params:', params);
// Example usage: accessing a specific parameter
const paramValue = params['paramName'];
console.log('Param value:', paramValue);
});
}
}