Search code examples
angularangular5

How to change page title with routing in Angular application?


Is there any npm module/ other way like React-Helmet that allows us to change page title as we route through our Angular application?

PS: I am using Angular 5.


Solution

  • You have a TitleService in Angular 5. Inject it in your component's constructor, and use the setTitle() method.

    import {Title} from "@angular/platform-browser";
    
    ....
    
    constructor(private titleService:Title) {
      this.titleService.setTitle("Some title");
    }
    

    Here are the docs from Angular: https://angular.io/guide/set-document-title