[英]How to pass index of an array from one component to another in angular2?
Currently I am using angular and I have an array in typescript file like this. 目前,我正在使用angular,并且在这样的打字稿文件中有一个数组。
var channelArray = {"channel1", "channel2", "channel3"}
In my html I have code like 在我的HTML中,我有类似的代码
<div *ngFor="let val of channelArray">
<de-series-prop></de-series-prop>
</div>
How do I pass the index of the array to series-prop component. 如何将数组的索引传递给series-prop组件。 I need the index value to assign some values in series-prop component. 我需要索引值才能在series-prop组件中分配一些值。
<div *ngFor="let val of channelArray; let i = index">
<de-series-prop [index]="i"></de-series-prop>
</div>
In your component: 在您的组件中:
@Input()
index: Number;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.