我有4个按钮,每个按钮都有唯一的值。我在控制台日志中使用当前代码未定义。
HTML
<button type="submit" class="parcel-btn weight-option" value="25" (click)="onItemSelector()">
<button type="submit" class="parcel-btn weight-option" value="50" (click)="onItemSelector()">
<button type="submit" class="parcel-btn weight-option" value="250" (click)="onItemSelector()">
<button type="submit" class="parcel-btn weight-option" value="100" (click)="onItemSelector()">
打字稿
onItemSelector() {
const weightSelector = this.elm.nativeElement.querySelectorAll('.weight-option').value;
console.log(weightSelector);
}
答案 0 :(得分:1)
试试这个
将值传递给onItemSelector函数
LayoutInflater
获取ts中的值
<button type="submit" class="parcel-btn weight-option" (click)="onItemSelector(25)">