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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:27:21  来源:igfitidea点击:

click event doesn't work, "co.console.log() is not a function"

angulartypescriptionic-frameworkionic2

提问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 alertor console.log, or anything.

我不知道问题是什么,因为当我尝试使用alertorconsole.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 tsfile 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 itemthen just do like this log(item)on htmlside and tsside log(data):void {}.

注意:如果你需要通过,item那么就log(item)htmlside 和tsside这样做log(data):void {}