我有菜單和二級菜單組件。我想根據router-outlet標籤中顯示的組件I來更改二級菜單中的項目。
我的菜單導航有多個層次(經典樹),但在二級菜單中,我只想顯示最後一層。Angular2 - 更改父路由器組件中的菜單路由器插座內的子組件
怎麼樣?我已經閱讀component-communication cookbook,我認爲問題可以通過父母和孩子通過服務進行交流來解決。
但我一直在問自己,如果這是解決這個問題的最好方法?
const routes: Routes = [
{ path: "", component: HomePage },
{
path: "team-support", component: TeamSupportPage, //secondary menu + router-outlet
children: [
{ path: '', component: TeamSupportHomePage },
{ path: 'add', component: TeamSupportTaskAddPage },
{
path: 'project/:id',
component: TeamSupportProjectPage, //this component should change secondary menu for TeamSupportPage component
children: [
{ path: '', component: TeamSupportProjectDashboardPage },
{ path: 'jobs', component: TeamSupportProjectJobsPage }
]
},
]
}
];
編輯: 我想實現,網上商店有,在那裏你可以深處導航相同的功能,但二級鏈接的變化:
當你根頁上,鏈接電腦,花園,工具,...
當你點擊電腦,鏈接更改爲:顯示器,硬盤,...
當您單擊監視器,鏈接更改爲:LED,OLED,平,...
變化是有條件的:如果較低的頁面沒有鏈接,則爲舊的被使用。我可以手動將它們添加到每個頁面,但我想避免將它們添加到每個頁面。
哪一個是次要的? –
當TeamSupportProjectDashboardPage被加載時,我想更改TeamSupportPage中定義的菜單(模板)。 – Makla
發佈TeamSupportProjectDashboardPage代碼 –