Angular 5中Angular@Angular/http URLSearchParams类的替代品是什么
我目前正在使用@angular/http URLSearchParams类来检索URL参数。在Angular 5中,注意到这是不推荐的,但我没有看到一个合适的类以我当前使用的方式替换URLSearchParamsAngular 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
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');}