如何注入数据到从路由器创建Angular2成分 [英] How to inject data into Angular2 component created from a router

查看:206
本文介绍了如何注入数据到从路由器创建Angular2成分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试图建立我们的Angular1应用程序(pretty复杂的)的Angular2原型(基于alpha44),我尝试使用路由和子路由时找到最好的模型/数据架构。

I'm currently trying to build an Angular2 prototype (based on alpha44) of our Angular1 app (pretty complex one) and I'm trying to find the best model/data architecture when using routes and child routes.

在我的例子,从路线创建一个子组件,我想访问父组件的属性(托管路由器出口)。

In my example, from a child component created from a route, I want to access a property of the parent component (hosting the router-outlet).

但是当你创建一个组件路由器出口,则不能使用 @input @Output 了。
那么,什么是注入一些数据/属性中的最佳实践,除了基本的 routeParams 和静态的RouteData

But when you create a component from a router-outlet, you cannot use @Input and @Output anymore. So what is the best practice to inject some data/properties, except basic routeParams and static routeData?

你如何与父组件没有太多的耦合沟通?

How do you communicate with the parent component without too much coupling?

推荐答案

您可以使用的RouteData 为了数据传递到路线。请参见这里和的此处。我仍然缺少从组件初始化这个数据obj的一部分(见<一href=\"http://stackoverflow.com/questions/34289761/angular-2-equivalent-to-router-resolve-data-for-new-router\">my有关问题)

You can use RouteData in order to pass data into routes. See here and here. I'm still missing the part of initialising this data obj from the component (see my question regarding)

这篇关于如何注入数据到从路由器创建Angular2成分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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