问题描述
我目前正在尝试为我们的Angular1应用程序(非常复杂的一个)构建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.
在我的示例中,我想从通过路由创建的子组件中访问父组件的属性(托管router-outlet
).
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
).
但是,当您从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?
推荐答案
共享服务可以与路由器添加的组件一起使用.有关详细信息,请参见 https://angular.io/docs/ts/latest/cookbook/component-communication.html
A shared service can be used with components added by the router. For details see https://angular.io/docs/ts/latest/cookbook/component-communication.html
data
支持也已添加到RC.4中的新路由器.有关详细信息,请参见如何传递数据Angular 2组件中同时使用路由?
data
support also was added to the new router in RC.4. For details see How do I pass data in Angular 2 components while using Routing?
这篇关于如何将数据注入到由路由器创建的Angular2组件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!