私はAngular 7アプリを構築しています。 このアプリでは、ネストされたルートがあります。親ルートが使用しているコンポーネントを検出できるようにしたい。私はそれをローカルで行う方法を見つけましたが、これはプロダクションでは機能しません(出力は異なります)。
私はこの方法を使用します:
checkIfChild() {
this.sub = this.route.parent.params.subscribe(params => {
if (params['id']) {
this.parentId = params['id'];
if (this.route.parent.component['name'] === 'ProjectShowComponent') {
this.parentType = 'Project';
} else if (this.route.parent.component['name'] === 'CompanyShowComponent') {
this.parentType = 'Company';
} else if (this.route.parent.component['name'] === 'ContactShowComponent') {
this.parentType = 'User';
}
}
});
}
メソッド this.route.parent.component ['name'] はローカルに名前を出力しますが、本番環境では文字 T だけを出力します。
代わりにこのメッセージが表示されます
TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.
親ルートが子ルートをアクティブにしたことを検出して、それを実行できるようにする正しい方法は何ですか?