如何从一个部件传递对象到另一个角2? [英] How to pass object from one component to another in Angular 2?
问题描述
我的角组件的第一和组件使用第二个作为的指令的。
他们应该分享同一型号的目标,这是第一个组件初始化。
我怎么能传递模型的第二个组成部分?
I have Angular components and first component uses the second one as a directive. They should share the same model object, which is initialized in the first component. How can I pass that model to the second component?
推荐答案
2组件,指令组件可以定义输入属性( @input
标注在打字稿)。和组件1可以在财产传给从模板指令组成部分。
Component 2, the directive component can define a input property (@input
annotation in Typescript). And Component 1 can pass that property to the directive component from template.
请参阅本SO回答<一个href=\"http://stackoverflow.com/questions/33966692/how-to-do-inter-communication-between-a-master-and-detail-component-in-angular2/33967426#33967426\">How在Angular2做了主从部件之间间的通信?
和输入是如何被传递到子组件。你的情况是指令。
and how input is being passed to child components. In your case it is directive.
这篇关于如何从一个部件传递对象到另一个角2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!