gpt4 book ai didi

javascript - 如何在ionic 2 angular 2中的点击事件中获取按钮的id和name值

转载 作者:太空狗 更新时间:2023-10-29 18:16:01 25 4
gpt4 key购买 nike

我有一个按钮

<button ion-button icon-left name="0x10000011 (click)="AppService.sendNotify($event)" id="0x10000011" value=1>
<ion-icon name="camera"></ion-icon>
CAM Icon
</button>

当我点击它时,我想在我的服务 sendNotify 函数中获取 id 属性。

public sendNotify(data) {
var method = 'SCAN_BUTTON';
var name = data.target.name;
var id = data.target.id;
var value = data.target.value - 0;
console.log("#$#$%$%^$%^#$%^#$%",method, name, value);
}

这里我没有得到按钮 idname。相反

#$#$%$%^$%^#$%^#$% SCAN_BUTTON undefined NaN.

谁能帮我找出我的错误?

最佳答案

您正在考虑 ionic 组分 ion-button成为一个基本的 html button 标签。

其实就是一个 Angular 分量。检查here .

它的内部 html 看起来像:

<span class="button-inner">
<ng-content></ng-content>
</span>
<div class="button-effect"></div>

根据您点击按钮的位置,它会随事件发送标签的 ID 和名称。点击区域可以是按钮标签 跨度

您应该简单地将值作为参数发送。

<button ion-button icon-left name="0x10000011" (click)="AppService.sendNotify($event,'0x10000011','0x10000011')" id="0x10000011" value=1>
<ion-icon name="camera"></ion-icon>
CAM Icon
</button>

A plunker to try

关于javascript - 如何在ionic 2 angular 2中的点击事件中获取按钮的id和name值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44225120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com