我一直在試圖學習angular 2以及本教程[Build an application with Angular 2 and Firebase][1]
並試圖擴展它。但是當試圖嵌套多條路線時,我遇到了一些障礙。子組件未在父路由更改上更新
應用結構:
Goals – (has router-outlet)
> Single Goal with Experiments list – (has router-outlet)
> Single Experiment – (has router-outlet)
> Experiment Notes
路由器設定:
export const routerConfig : Route[] = [
{
path: 'goals',
children: [
{
path: ':id', component: SingleGoalComponent,
children: [
{
path: 'experiments',
children: [
{ path: ':id', component: ExperimentDetailsComponent,
children: [
{ path: '', redirectTo: 'notes', pathMatch: 'full' },
{ path: 'notes', component: ExperimentNotesComponent }
]
},
{ path: 'new', component: NewExperimentComponent },
{ path: '' }
]
},
{ path: '', redirectTo: 'experiments', pathMatch: 'full' }
]
},
{ path: '', component: GoalsComponent }
]
},
{ path: 'notes', component: NotesComponent },
{ path: '', redirectTo: 'goals', pathMatch: 'full' },
{ path: '**', redirectTo: 'goals', pathMatch: 'full' }
];
的問題
如果我在實驗列表點擊實驗1我克ot到goals/1/experiments/1/notes
該網址是正確的,我看到了正確的實驗1的註釋。
如果我再點擊實驗2在實驗列表goals/1/experiments/2/notes
的URL是正確的實驗細節是正確的,但在紙幣仍在實驗1個的Notes。
如果我再刷新瀏覽器,實驗2個負載和筆記現在實驗2個的Notes這是正確的。
這是我如何得到experimentId
檢索票據
實驗,notes.component.ts
experimentId: string;
goalId: string;
constructor(
private router: Router,
private route: ActivatedRoute,
private experimentsService: ExperimentsService,
private _location: Location) { }
ngOnInit() {
Observable.combineLatest(this.route.parent.params, this.route.parent.parent.params)
.forEach((params: Params[]) => {
this.experimentId = params[0]['id'];
this.goalId = params[1]['id'];
});
console.log('Experiment ID: ' + this.experimentId + '| Goal Id: ' + this.goalId);
this.notes$ = this.experimentsService.findAllNotesForExperiment(this.experimentId);
我敢肯定,這是一個明顯的錯誤,我正在做,但對於我的生活我無法看到我的錯在哪裏。