0

Currently I am using angular and I have an array in typescript file like this.

var channelArray = {"channel1", "channel2", "channel3"}

In my html I have code like

<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. I need the index value to assign some values in series-prop component.

1
  • You mean a JS object. Commented Jul 22, 2018 at 2:39

2 Answers 2

1
<div *ngFor="let val of channelArray; let i = index">
  <de-series-prop [index]="i"></de-series-prop>
</div>

In your component:

@Input()
index: Number;
Sign up to request clarification or add additional context in comments.

Comments

0

*ngFor exposes the index as a local variable.

<li *ngFor="let item of items; let i = index; trackBy: trackByFn">...</li>

You can see the documentation here.

1 Comment

Thanks for this info.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.