如何在Angular 4中单击按钮的值

时间:2017-07-13 04:31:43

标签: javascript angular typescript

我有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);
}

1 个答案:

答案 0 :(得分:1)

试试这个

将值传递给onItemSelector函数

LayoutInflater

获取ts中的值

   <button type="submit" class="parcel-btn weight-option" (click)="onItemSelector(25)">