javascript - 在表单模态内单击 ng-click 不会触发事件

标签 javascript angularjs ionic-framework

我刚刚编写了一个打开模式的简单按钮。在此模式中,我放置了一个“关闭”按钮,该按钮触发了一个运行良好的“closeLogin()”函数。与我在登录表单中创建一个啤酒按钮以启动“doTestme()”函数的方式相同,但它从未启动过。请看下面:

正确触发模态的按钮:

<script id="templates/home.html" type="text/ng-template">
  <ion-view view-title="Welcome">
    <ion-content class="padding">
      <button type="button" class="button" ng-click="login()">Log-in Test, click on the beer!</button>
    </ion-content>
  </ion-view>
</script>

为此处理 $scope 的“MainCtrl”:

  .controller('MainCtrl', function($scope, $ionicSideMenuDelegate, $ionicModal, $timeout) {
  $scope.loginData = {};

  // Create the login modal that we will use later
  $ionicModal.fromTemplateUrl('templates/login.html', {
    scope: $scope
  }).then(function(modal) {
    $scope.modal = modal;
  });

  // Triggered in the login modal to close it
  $scope.closeLogin = function() {
    $scope.modal.hide();
  };

  // Open the login modal
  $scope.login = function() {
    $scope.modal.show();
  };

  $scope.doTestme = function() {
    alert("test ok");
  };

正确弹出的模态:

<script id="templates/login.html" type="text/ng-template">
<ion-modal-view>
  <ion-header-bar>
    <h1 class="title">Login</h1>
    <div class="buttons">
      <button class="button button-clear" ng-click="closeLogin()">Close</button>
    </div>
  </ion-header-bar>
  <ion-content>
    <form ng-submit="doLogin()">
      <div class="list">
    <label class="item item-input">
      <span class="input-label">Username</span>
      <input type="text" ng-model="loginData.username">
    </label>
    <label class="item item-input">
      <span class="input-label">Password</span>
      <input type="password" ng-model="loginData.password" style="-webkit-flex: 1 0 100px;"><button type="button" ng-click="doTestme()" class="button button-icon ion-beer" style="font-size:35px;"></button>
    </label>
    <label class="item">
      <button class="button button-block button-positive" type="submit">Log in</button>
    </label>
  </div>
</form>
  </ion-content>
</ion-modal-view>
</script>

就好像 ng-click 从未被观看过,我在控制台中没有任何错误,无法调试它,所以...有什么想法吗?

这是代码笔:http://codepen.io/anon/pen/jEpNGB

最佳答案

你不应该在标签内使用按钮。它不会正常工作。 只需将容器从 <label> 更改为至 <div>

<div class="item item-input">
          <span class="input-label">Password</span>
          <input type="password" ng-model="loginData.password" style="-webkit-flex: 1 0 100px;">
           <button type="button" ng-click="doTestme()" class="button button-icon ion-beer" style="font-size:35px;"></button>
        </div>

检查此工作 codepen

关于javascript - 在表单模态内单击 ng-click 不会触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28827341/

相关文章:

javascript - Angular 2 : external js file variables are accessible from component

javascript - 在 gulp/typescript 生产构建中禁用 AngularJS 调试数据

javascript - 如何使用 ng-click 功能显示 ionic 图标(fa 图标)?

javascript - ionic 和 AngularJS : How to retain state between navigations?

ionic-framework - 更改消息或删除确认警报以在 IOS 中使用 facebook 登录(我使用的是 IONIC 5)

javascript - 使用javascript/php批量打印?

javascript - 更改一个选择菜单会禁用网页上的另一个选择菜单?

javascript - 在 Ajax 上加载 Google Chart -- 成功

javascript - Angular 单页应用程序,videoJS 就绪功能仅在页面加载时触发

javascript - 如何将 Angular ngmodel 与 jQuery UI slider 一起使用?