How to pass a string to an Angular 2 function (click)?

I have a div element in my HTML so that

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

My question is: how do I 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 pattern error.

Enyone can help?

+4
source share
3 answers

You need to wrap the whole expression in quotation marks if it contains quotation marks:

<div (click)="onPaginationClick('myString')">next</div>
+10
source

you need to use nested quotes:

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

In component.ts

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

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

In the .html component

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

Source: https://habr.com/ru/post/1650660/


All Articles