我有一個帶有路由器插座的組件。這個組件有一個select元素,我通過服務在ngOnInit上提供了一些類別。有3條子路線,其中一條導航到一個也希望使用這些類別的組件。角度2:將數據從父項傳輸到子項
我的路線是這樣的
const routes: Routes = [
{
path: 'marketplace',
component: MarketplaceComponent,
resolve: { categories: CategoriesResolveService },
canActivate: [AuthenticatedGuard],
children: [
{ path: 'modules', component: ModulesComponent, resolve: { categories: CategoriesResolveService } }
]
}];
這是使2 HTTP調用獲得類別。我怎樣才能將這些數據傳輸給子組件?我想避免再做一次http調用。是否有可能在父母和孩子之間分享這些數據?
你嘗試用viewChild()? –
不知道viewChild是什麼,會看一看,謝謝 –
ViewChild通過在父模板中聲明子組件來工作?如果是這樣,那麼我認爲它不會在這種情況下工作,我只有路由器插座。 –