简体   繁体   English

将数据传递到角度4中的自定义组件

[英]Pass data to custom component in angular 4

I have a custom component with a selector how do i pass data to it in angular 4 to show data in its template. 我有一个带有选择器的自定义组件,该如何将数据以角度4传递给它,以在其模板中显示数据。 like 喜欢

<my-component data="shirts"></my-component>

And in my-component template 在我的组件模板中

<h5>{{data.size}}</h5>

Not sure how to pass data down from parent to child component in angular 4. 不知道如何在角度4中将数据从父组件向下传递到子组件。

If "data" variable it's an @Input() property, "data" should be between brackets to allow data binding. 如果“ data”变量是@Input()属性,则“ data”应放在方括号之间以允许数据绑定。

<my-component [data]="shirts"></my-component>

You need to have this in your component: 您需要在组件中包含以下内容:

@Input() data;

Don't forget to import "Input" from @angular/core 不要忘记从@ angular / core导入“输入”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM