Developer Snippet Diary

Angular | Set Page title dynamically based on API call

  1. Import the Title service in your component:
import { Title } from '@angular/platform-browser';

2. Inject the Title service in the constructor of your component:

constructor(private titleService: Title) {}

3. Set the page title using the setTitle method of the Title service in the subscribe callback:

this.pageTitle = data.PageTitle;
this.titleService.setTitle(this.pageTitle); // Set the page title dynamically

 

 

Posted by: Muhammad Farhan
Email: helpinghour@gmail.com