0

I am currently trying to pass some indexes to a function but the first parameter (ii) returns undefined.

<div *ngFor="let tab of screen.data.tabs; let index = i;">
    <div *ngIf="tab.active">
        <div *ngIf="tab.questions">
            <div *ngFor="let question of tab.questions; let index = ii;">
                <div class="scenarioContainerQUESTION">
                    <p [innerHtml]="question.text"></p>
                    <div *ngFor="let option of question.options; let iii = index;" class="option" [ngClass]="{'optionSelected': option.selected}">
                        <label [for]="ii+'_'+iii">{{option.text}}</label>
                        <input [id]="ii+'_'+iii" [name]="'group'+ii" type="radio" [value]="ii" (click)="optionClicked(ii,iii)" />
                    </div>
                    <button [ngClass]="{'fade': selectedOption == -1}" (click)="ManageSubmit()">SUBMIT</button>
                </div>
            </div>
        </div>
    </div>
</div>
3
  • are you actually using ng2, or the latest - ng5? Commented May 3, 2018 at 2:10
  • 1
    Try let i = index and let ii = index (only let iii = index is OK). Commented May 3, 2018 at 2:13
  • @pixelbits I am using ng5 Commented May 3, 2018 at 2:14

2 Answers 2

1

You should assign index value to the variables not the otherway,

<div *ngFor="let tab of screen.data.tabs; let i= index;">

also

<div *ngFor="let question of tab.questions; let ii= index;">
Sign up to request clarification or add additional context in comments.

1 Comment

i Knew it would be something tiny haha thanks everyone for the quick resonse.
0

Check out the docs for ngFor. The correct syntax for binding to index:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.