Angular 5 中 Angular @angular/http URLSearchParams 类的替代品是什么

2024-01-02

我目前正在使用 @angular/http URLSearchParams 类来检索 URL 参数。在 Angular 5 中,值得注意的是,这已被弃用,但我没有看到一个合适的类可以以我当前使用的方式替换 URLSearchParams。

constructor() { 
    this.urlSearchParams = new URLSearchParams(window.location.search.substring(1));
    this.custno = this.urlSearchParams.get('custno');
    this.plan = this.urlSearchParams.get('plan');
}

注意:我没有使用 appRoutingModule,因为它对于我正在创建的 SPA 来说太过分了。

在这种情况下替换 @angular/common/http URLSearchParams 类的正确解决方案是什么?


替代品是HttpParams.

import { HttpParams } from '@angular/common/http';

来自 Angular 的官方文档。 https://angular.io/api/common/http/HttpParams

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular 5 中 Angular @angular/http URLSearchParams 类的替代品是什么 的相关文章

随机推荐