Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angular – ActivatedRoute.queryParams未定义大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用Angular 2.0捕获查询字符串参数,并且我很难过.我有一个这样的网址

http://localhost:5000/?id_token=eyJ0eXAiO ….

我希望能够在路由占用之前捕获id_token的值,并且我丢失了参数.我发现了这个GitHub问题线程

https://github.com/angular/angular/issues/9451

但是这使用了一种不再适用的弃用方法.我尝试了以下方法

var foo = this.activatedRoute.queryParams.subscribe(params => {
        console.log(params);
        let id = params['id_token'];
        console.log(id);
    });


   console.log(this.router.routerState.snapshot.root.queryParams["id_token"]);

   var bar = this.activatedRoute.params.subscribe(
        (param: any) => console.log(param['id_token']));

我在构造函数中尝试了这些方法以及我的组件的ngOnInit(),但控制台始终显示未定义.我是在错误的地方做这件事吗我根本无法更改QS,因为它是由Azure AD创建的.

尝试注入ActivatedRoute并使用route.snapshot.queryParams [‘name’]获取queryParam,如下所示:
class someComponent implements OnInit {
    constructor(private route: ActivatedRoutE) { }
    ngOnInit(): void {
        let value = this.route.snapshot.queryParams['name'];
    }
}

通过router.navigate设置queryParams的工作方式如下:

class someComponent {
    constructor(private router: Router) { }
    goSomewhere(): void {
        this.router.navigate(['somewhere'],{ queryParams: { name: 'value' } });
    }
}

大佬总结

以上是大佬教程为你收集整理的angular – ActivatedRoute.queryParams未定义全部内容,希望文章能够帮你解决angular – ActivatedRoute.queryParams未定义所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。