1

This seems simple but it doesn't work. I am making pagination for a list of things. I have a pagination object that is defined as such:

in my models.ts:

export interface PageLink {
    displayText: string;
    pageNumber: number;
    status: string;
}

in my controller:

pageLinks: Array<PageLink>;

in my html:

<a *ngFor="let link of pageLinks" (click)="togglePage('test')" class="{{link.status}}">{{link.displayText}}</a>

This all works without blowing up, however my desire was to have the pageNumber parameter of the PageLink object put inside of the togglePage() function. Doing this however:

<a *ngFor="let link of pageLinks" (click)="togglePage('{{link.pageNumber}}')" class="{{link.status}}">{{link.displayText}}</a>

Blows up. When i do this i get very many lines of error in my console however the gist of the error is this:

Got interpolation ({{}}) where expression was expected

Why does this happen, and how can i avoid it?

Note: This is Angular 5

1
  • 1
    Try this: (click)="togglePage(link.pageNumber)" Commented Feb 8, 2018 at 17:26

2 Answers 2

4

No need to use interpolation. Whatever you have been passed to inside event attribute, it is going to evaluate against component context directly. The value of pageNumber would passed to togglePage function directly.

(click)="togglePage(link.pageNumber)"
Sign up to request clarification or add additional context in comments.

1 Comment

That's it. thanks. I don't completely understand why this works but at least it does... (I'll accept your answer as soon as the system lets me)
1

This will work.No need to use interpolation

  <a *ngFor="let link of pageLinks" 
(click)="togglePage(link.pageNumber)" class="{{link.status}}">{{link.displayText}}</a>

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.