typescript 单击事件不起作用,“co.console.log() 不是函数”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43429938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
click event doesn't work, "co.console.log() is not a function"
提问by Eoin Maloney
I've been trying to get a button to work to bring up a page, passing an object in the parameters, but for some reason, it gives me the error
我一直试图让一个按钮来打开一个页面,在参数中传递一个对象,但由于某种原因,它给了我错误
"co. is not a function."
“co. 不是函数。”
I don't know what the problem is because it gives me the same error when I try to use alert
or console.log
, or anything.
我不知道问题是什么,因为当我尝试使用alert
orconsole.log
或任何东西时,它给了我同样的错误。
page HTML:
页面HTML:
<ion-header>
<ion-navbar>
<ion-title>SearchResults</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list>
<ion-item *ngFor= "let item of resultArray;">
<img src={{item.thumbnail}} />
<p>{{item.title}}</p>
<button bookDetail (click)="console.log(\"Even some text, please?\")">DETAIL</button>
</ion-item>
</ion-list>
</ion-content>
回答by Sampath
On your ts
file just do like below.
在您的ts
文件上,请执行以下操作。
.ts
.ts
log():void {
console.log('Your message here');
}
html
html
<button ion-button (click)="log()">DETAIL</button>
Note:If you need to pass the item
then just do like this log(item)
on html
side and ts
side log(data):void {}
.
注意:如果你需要通过,item
那么就log(item)
在html
side 和ts
side这样做log(data):void {}
。