gpt4 book ai didi

javascript - Angular2 queryParams 抛出 "does not exist on type"错误

转载 作者:太空狗 更新时间:2023-10-29 17:46:52 24 4
gpt4 key购买 nike

我得到了一个 Angular2 服务,它应该从类似 http://localhost:3001/?foobar=1236 的 URL 返回参数

import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import 'rxjs/add/operator/map';

@Injectable()

export class ParameterService {
constructor(private route: ActivatedRoute) { }

getParameter() {
return this.route.snapshot.queryParams.foobar;
}
}

但是当我调用服务的 getParameter() 方法时出现错误:

error TS2339: Property 'foobar' does not exist on type '{ [key: string]: any; }'

并在错误发生后返回正确的结果。我可以毫无问题地使用调试器访问 foobar 参数。有人有类似的问题吗?我可以想象它会提前调用吗?

(可能重复:angular2 rc6: Property queryParams does not exist on type RouterState)

最佳答案

这是获取参数的方式:

this.route.snapshot.queryParams['foobar'];

关于javascript - Angular2 queryParams 抛出 "does not exist on type"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39592825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com