7

I have a div element in my HTML like so

<div (click) = onPaginationClick()>next</div>

My question is : How to pass a string to the onPaginationlick() function ? when i try to pass it like this :

<div (click)=onPaginationClick("myString")>next</div>

I have a parse template error.

Enyone can help ?

3 Answers 3

21

You need to wrap the whole expression in quotes if it itself contains quotes:

<div (click)="onPaginationClick('myString')">next</div>
Sign up to request clarification or add additional context in comments.

2 Comments

@gunther, what if i need to evaluate a value in place of my string
@VinaySingh then omit the quotes. Not sure what the problem is.
2

you need to use nested quotes:

<div (click)="onPaginationClick('helloworld')">next</div>

Comments

1

In your component.ts

import { Component } from '@angular/core';

@Component({
  ...
})
export class AppComponent {
  ...
  onPaginationClick(value): void {
     ...
  }
}

In your component.html

<div (click)="onPaginationClick('helloworld')">next</div>

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.