私のアプリケーションルートコンポーネントでは、コンテナ内にいくつかのスタイルを持つrouter-outlet
があります。 ChildContainerで変数を取得するためにAngular2がapp-rootの子ルートからデータを取得しています
{
path: 'some-path',
component: ChildContainer,
data: { variable:'variable' },
}
そして、私がすることができますが、私はAPPROOTでそれを必要とする: は私がルートを持っています。だから、documentationから私はchild
からそれを得ることができますが、私はAPPROOTコンストラクタでこれを行う場合:
const state: RouterState = router.routerState;
const root: ActivatedRoute = state.root;
const child = root.firstChild;
とconsole.log(root, child)
- 子供がnullであり、根は(プロパティのゲッターを呼び出す)正しい子が含まれています。 AppRootでvariable
を取得するにはどうすればよいですか?
ありがとうございますが、少し違います。私の場合は、ルータデータから変数を取得する必要があります。https://angular.io/docs/ts/latest/api/router/index/ActivatedRoute-interface.html#!#data-anchor –
@qweasd:あなたのコメント、乾杯! –