我正在使用Angular 4+在当前项目中处理仪表板布局。
当用户在应用程序的不同部分之间导航时,我需要navmenu标头标题进行更新以反映应用程序的当前部分。
例如,当用户访问设置时,“页面标题”应更改为“设置”
该项目基于.net core 2 Angular模板。下面是我必须组成应用程序路由以及仪表板路由的代码。
导航服务
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class NavigationService {
private titleSource = new BehaviorSubject<string>("Page Title");
currentTitle = this.titleSource.asObservable();
constructor() {
}
changeTitle(title: string) {
this.titleSource.next(title);
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序路由模块
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from "./components/home/home.component";
const appRoutes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', …Run Code Online (Sandbox Code Playgroud)