How to Know Which component is loaded in router-outlet in Angular 5 and above

后端 未结 2 1665
时光取名叫无心
时光取名叫无心 2021-01-06 06:14

This my ap.component.html




         


        
2条回答
  •  青春惊慌失措
    2021-01-06 06:58

    You need to handle this inside the component or based on a variable, you can use url property of the router to get the current component url

    constructor(router: Router) {
    this.router.events.subscribe((event: Event) => {
                console.log(event.url); //based on this change class
        });
    }
    

提交回复
热议问题