Angular 6 - Get current route and it's data

前端 未结 3 1856
离开以前
离开以前 2020-12-29 09:09

How do you able to get current route you\'re in and get\'s it\'s data, children and it\'s parent?

say if this is the route structure:

3条回答
  •  [愿得一人]
    2020-12-29 09:44

    You can access the route's data property from the snapshot like this:

    import { Component, OnInit } from '@angular/core';
    import { ActivatedRoute } from '@angular/router';
    
    @Component({
        templateUrl: './app/home/welcome.component.html'
    })
    export class WelcomeComponent implements OnInit {
        public pageTitle: string;
    
        constructor( private route: ActivatedRoute) {
        } 
    
        ngOnInit(): void {
         this.pageTitle = this.route.snapshot.data['title'];
      }
    
    }
    

提交回复
热议问题