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.
Steps to detect route change in Angular application Urls. Import Router, Event, NavigationStart, NavigationEnd, NavigationError from '@angular/router'. And inject router in the constructor. Subscribe to the NavigationStart, NavigationEnd, NavigationError events of the router.
A service that can be used to get and set the title of a current HTML document. class Title { getTitle(): string setTitle(newTitle: string) }
Angular provides extensive set of navigation feature to accommodate simple scenario to complex scenario. The process of defining navigation element and the corresponding view is called Routing. Angular provides a separate module, RouterModule to set up the navigation in the Angular application.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With