Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 5中Angular@Angular/http URLSearchParams类的替代品是什么_Angular - Fatal编程技术网

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

Angular 5中Angular@Angular/http URLSearchParams类的替代品是什么,angular,Angular,我目前正在使用@angular/http URLSearchParams类来检索URL参数。在Angular 5中,注意到这是不推荐的,但我没有看到一个合适的类以我当前使用的方式替换URLSearchParams constructor() { this.urlSearchParams = new URLSearchParams(window.location.search.substring(1)); this.custno = this.urlSearchParams.ge

我目前正在使用@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');
}
注意:我没有使用和批准模块,因为它对于我正在创建的SPA来说是多余的


在此上下文中,替换@angular/common/http URLSearchParams类的正确解决方案是什么?

替换为
HttpParams

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

看看
URLSearchParams
文档,它们明确指出您应该使用
@angular/common/http
:这些文档在这种情况下没有多大帮助。他们提到使用
@angular/common/http
,但没有提到要替换
URLSearchParams
的特定类。。。是的,我看这个可以用。我将实现这个,并看看它是如何运行的。我发现我在帖子中引用了错误的软件包,应该是@angular/http。谢谢你的指导。下面的代码按照我的需要执行:
constructor(){this.httpParams=newhttpparams({fromString:window.location.search.substring(1)});this.custno=this.httpParams.get('custno');this.plan=this.httpParams.get('plan');}