Parent components gets empty Params from ActivatedRoute

前端 未结 5 1420
小鲜肉
小鲜肉 2020-12-08 14:51

I have a main component that has a router-outlet in it. In the component that is loaded in the router-outlet I grab the url parameter like this:

ngOnInit():         


        
5条回答
  •  青春惊慌失措
    2020-12-08 15:07

    The Very simple answer

    import { Component } from '@angular/core';
    import { Router, ActivatedRoute, Params, RoutesRecognized } from '@angular/router';
    
    export class AppComponent {
    
        constructor(private actRoute: ActivatedRoute, private router: Router){}
    
        ngOnInit(): void {
            this.actRoute.firstChild.params.subscribe(
                (params: any) => {
                    if (params.hasOwnProperty('') != '') {
                        //do whatever you want
                        console.log(params.);
                    } 
                });
        }
    }
    

提交回复
热议问题