有没有办法在 Angular 路由模块的路由列表中注入和使用服务以动态更改路由数据?
像这样:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { MyComponent } from './my/my.component';
const routes: Routes = [
{ path: 'about', component: AboutComponent, data: {title: myService.getTitle()}} // use it?
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
constructor(private myService: SomeService) {} // inject it
}
如何在路由数组中实现动态行为,例如设置自定义标题?