8

Angular had many changes in the beta, my issue is that try to use pipes and the index in a ngFor and i get this message:

Parser Error: Unexpected token = and

The pipe 'let' could not be found  

when i use this code:

 <div style="overflow-y: scroll; max-height: 200px;">
        <div (click)="showComentario(index);" *ngFor="let comment of comentarios| filterSource:selectedSource | let index=index; ">
            {{comment.comment}}
        </div>
    </div>

if i change the order like this:

<div style="overflow-y: scroll; max-height: 200px;">
    <div (click)="showComentario(index);" *ngFor="let comment of comentarios;let index=index;| filterSource:selectedSource |  ">
        {{comment.comment}}
    </div>
</div>

i get this message:

Template parse errors:
TypeError: key[0] is undefined  



Parser Error: Unexpected token |, expected identifier, keyword, or string at column 47 in [let comment of comentarios; let index=index; 

How i can use pipes and index at the same time?

EDIT: I modified the code as the comments suggested like this:

<div style="overflow-y: scroll; max-height: 200px;">
    <div (click)="showComentario(index);" *ngFor="let comment of comentarios | filterSource:selectedSource;let index=index ">
        {{comment.comment}}
    </div>
</div>

i keep getting these errors: TypeError: key[0] is undefined and Parser Error: Unexpected token |

3
  • 1
    remove the | pipe from end of ngFor expression.. Commented May 16, 2017 at 20:58
  • 1
    yes, and replace it with a semicolon. let x of y | zzz; let index=index Commented May 16, 2017 at 21:01
  • @dbandstra changed the code, still getting the same errors =/ Commented May 16, 2017 at 21:16

1 Answer 1

27

try below,

<div (click)="showComentario(i)" *ngFor="let comment of comentarios | filterSource : selectedSource; index as i" >
  {{comment.comment}}
</div>

Hope this helps!!

Sign up to request clarification or add additional context in comments.

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.