【问题标题】:data-toggle='button' only after condition check in angular componentdata-toggle='button' 仅在角度组件中的条件检查后
【发布时间】:2019-09-05 17:55:23
【问题描述】:

点击时需要检查一些条件,如果返回true,则切换点击的位置

<div class="btn-group btn-group-toggle" data-toggle="buttons">
    <label class="btn btn-secondary active" (click)='example()'>
        <input type="radio" name="options" id="option1" autocomplete="off" checked> Active
    </label>
    <label class="btn btn-secondary"  (click)='example()'>
        <input type="radio" name="options" id="option2" autocomplete="off"> Radio
    </label>
    <label class="btn btn-secondary"  (click)='example()'>
        <input type="radio" name="options" id="option3" autocomplete="off"> Radio
    </label>
</div>

【问题讨论】:

  • 您可以将$event 传递给example(),这样您就可以访问事件属性,例如targettarget.name/target.id。至少尝试以下方法。更改模板中的处理程序以传递$event (click)='example($event)'。然后更新处理程序以获取$event 参数并根据需要使用它example($event) { console.log($event.target); }?

标签: html angular user-interface bootstrap-4


【解决方案1】:

你可以使用这样的方法:

status:boolean;
someMethod(value: string): void {
this.status = value;

if (your condition) {
  //Your operation here
} else {
 //your other work.
}

}

此处的状态将帮助您存储值并应用您的条件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 2013-09-09
    • 1970-01-01
    相关资源
    最近更新 更多