Angular小博客
分享让你更聪明
很多时候每一个页面都需要不同的Title,下面是Angular修改浏览器title的两种方法。
import {Routes} from '@angular/router';
export const routes: Routes = [
{path: '', loadComponent: () => import('./pages/index/index.component').then(m => m.IndexComponent), title: '首页'},
{path: 'list', loadComponent: () => import('./pages/list/list.component').then(m => m.ListComponent), title: '列表'},
{path: 'details', loadComponent: () => import('./pages/details/details.component').then(m => m.DetailsComponent), title: '详情'},
];
import {Title} from "@angular/platform-browser";
export class IndexComponent implements OnInit {
constructor(private title: Title) {}
ngOnInit(): void {
setInterval(() => {
this.title.setTitle('博客www.ng1024.com');
}, 2000)
}
}