Angular:将查询参数附加到 URL [英] Angular: append query parameters to URL
本文介绍了Angular:将查询参数附加到 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用这个:
import { HttpParams } from '@angular/common/http';
let params = new HttpParams();
params.append('newOrdNum','123');
但这不起作用,我没有在 url 中附加参数.有什么建议吗?
But this is not working, i dont append param in url. Any suggestion?
推荐答案
这可以通过使用 Router
类来存档:
This could be archived by using the Router
class:
使用组件:
import { Router, ActivatedRoute } from '@angular/router';
@Component({})
export class FooComponent {
constructor(
private _route: ActivatedRoute,
private _router: Router
){}
navigateToFoo(){
// changes the route without moving from the current view or
// triggering a navigation event,
this._router.navigate([], {
relativeTo: this._route,
queryParams: {
newOrdNum: '123'
},
queryParamsHandling: 'merge',
// preserve the existing query params in the route
skipLocationChange: true
// do not trigger navigation
});
}
}
For more info check this book and the angular Router API
这篇关于Angular:将查询参数附加到 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文