角度:将查询参数附加到URL [英] Angular: append query parameters to URL

查看:112
本文介绍了角度:将查询参数附加到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类将其存档:

使用组件:

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
    });
   }
}

有关更多信息,请参见这本书和angular 路由器API

For more info check this book and the angular Router API

这篇关于角度:将查询参数附加到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆