How to change title of a page using angular(angular 2 or 4) route?

后端 未结 2 1672
情书的邮戳
情书的邮戳 2020-12-16 11:17

I want to change the title of the page whenever I click or browse the link from the URL bar. How to change that using Angular route? I am using angular version 4 and angular

2条回答
  •  既然无缘
    2020-12-16 12:20

    You can to use @angular/platefor-browser to use the setTitle():

    import { Title } from '@angular/platform-browser';
    
    @Component({
      selector: 'your-component',
    })
    
    export class YourComponent implements onInit {
      constructor(private title: Title) {}
    
     ngOnInit() {
         this.title.setTitle('Title for this component');
     }
    
    }
    

提交回复
热议问题