我的HTML中有一个div元素,如此
<div (click) = onPaginationClick()>next</div>
我的问题是:如何将字符串传递给onPaginationlick()函数?当我试图像这样传递它时:
<div (click)=onPaginationClick("myString")>next</div>
我有一个解析模板错误。
Enyone可以提供帮助吗?
答案 0 :(得分:12)
如果整个表达式本身包含引号,则需要将整个表达式包装在引号中:
<div (click)="onPaginationClick('myString')">next</div>
答案 1 :(得分:2)
您需要使用嵌套引号:
<div (click)="onPaginationClick('helloworld')">next</div>
答案 2 :(得分:0)
在 component.ts
中 "@angular/animations": "^4.1.1",
"@angular/cli": "^1.0.3",
"@angular/common": "^4.1.1",
"@angular/compiler": "^4.1.1",
"@angular/compiler-cli": "^4.1.1",
"@angular/core": "^4.1.1",
"@angular/forms": "^4.1.1",
"@angular/http": "^4.1.1",
"@angular/material": "^2.0.0-beta.3",
"@angular/platform-browser": "^4.1.1",
"@angular/platform-browser-dynamic": "^4.1.1",
"@angular/platform-server": "^4.1.1",
"@angular/router": "^4.1.1",
在 component.html
中import { Component } from '@angular/core';
@Component({
...
})
export class AppComponent {
...
onPaginationClick(value): void {
...
}
}