来自路由器插座的 Angular 2 输出 [英] Angular 2 output from router-outlet

查看:19
本文介绍了来自路由器插座的 Angular 2 输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从在路由器插座内呈现的子组件进行导航.我的父组件有一个路由器配置,我想在某个事件上手动导航.但我不知道如何在没有输出的情况下将一些数据(用于导航)从孩子传递给父母.因为这个结构不起作用

I want to make navigation from child components that render inside router-outlet. My parent component have a router config and I want to navigate manually on some event. But I don't know how I can pass from child to parent some data (for navigation) without output. Because this construction is non working

 <router-outlet (navigateTo)="navigateToMessagePart($event)"></router-outlet>

我怎样才能以正确的方式做到这一点?也许从孩子那里导航?但是我如何从孩子那里获得父方法.非常感谢您的帮助!

How I can do it in right way? Maybe navigate it from child? But how I can get parent methods from child. Many thanks for any help!

推荐答案

只是添加路由组件的占位符.不支持任何类型的绑定.

<router-outlet></router-outlet> is just a placeholder for adding routed components. There is no support for any kind of binding.

您可以创建一个自定义的 ,它允许您这样做或更常见,使用共享服务在父组件和路由组件之间进行通信.

You can create a custom <router-outlet> that allows you to do that or more common, use a shared service to communicate between parent component and routed component.

更多详情请见https://angular.io/docs/ts/latest/cookbook/component-communication.html

更新

现在有一个允许获取添加组件的事件

There is now an event that allows to get the added component

<router-outlet (activate)="componentAdded($event)" (deactivate)="componentRemoved($event)"></router-outlet>

允许与 componentAdded()

共享服务是首选方式.

这篇关于来自路由器插座的 Angular 2 输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆