【问题标题】:Create clickable buttons in Ionic v1 card在 Ionic v1 卡中创建可点击按钮
【发布时间】:2018-04-20 14:40:52
【问题描述】:

我有一个 Ionic v1 项目,我正在对其进行一些改进。

我有一张卡片列表,卡片本身可以点击,让用户了解更多详细信息。我需要在卡片上添加几个按钮,但我无法让按钮捕获点击 - 点击转到卡片 href。示例代码如下。

    <div class="list card" ng-repeat="(evtKey, evtObj) in someHash">
        <div class="item" ng-click="clickCard(evtKey)">
          <div class="row">
            <div class="col-20 row-center">
                <div> Some stuff here</div>
            </div>
            <div class="col-80 item-text-wrap">
                <div> More stuff here </div>
                    <div class="row text-center">
                        <div class="col col-33">
                            <div> More stuff </div>
                        </div>
                        <div class="col col-33">
                            <button class="button button-small button-stable" ng-click="alert('Yes')">Yes</button>
                        </div>
                        <div class="col col-33">
                            <button class="button button-small button-stable" ng-click="alert('No')">No</button>
                        </div>
                    </div>
                </div>
            </div>
            <p class="item-icon-right"><i class="icon ion-chevron-right icon-accessory"></i></p>
      </div>
  </div>

寻求有关如何使按钮而不是卡片捕获按钮的点击的帮助。到目前为止,我发现的示例都是使用 Ionic v2 及更高版本而不是 v1。

谢谢,

-S

【问题讨论】:

    标签: angularjs ionic-framework


    【解决方案1】:

    event.stopPropagation() 将停止从父元素调用事件。并且不要在 ng-click 中添加警报

    <div class="col col-33">
          <button class="button button-small button-stable" type="button" ng-click="somefunc('Yes');$event.stopPropagation();">Yes</button>
    </div>
    <div class="col col-33">
           <button class="button button-small button-stable" type="button" ng-click="somefunc('No');$event.stopPropagation();">No</button>
     </div>
    

    【讨论】:

      猜你喜欢
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多