ng-click控制器上的exec函数两次

时间:2016-05-16 10:56:49

标签: angularjs

HTML

<form id="newSaveForm">
<div class="item">
    <div class="list">
      <label class="item item-input">
        <input  type="date" ng-model="dateSave" placeholder="Date" required>
      </label>
    </div>
    <div class="list">
      <label class="item item-input">
        <input type="number" ng-model="moneySave" placeholder="Deposit?" required>
      </label>
    </div>
  <button class="button button-block button-balanced ion-android-checkbox-outline" data-ng-click="addMoney(dateSave,moneySave)" ng-disabled="buttonDisabled"> Save  </button>
</div>
</form>

的JavaScript

.controller('saveCtrl', function($scope, $state, $http, $filter) {
  getAll();

  $scope.addMoney = function(tgl, jml) {
    $scope.buttonDisabled = true;
    $http.post("http://localhost/mymoney/insert.php?jml=" + jml + "&tgl=" + conv_date(tgl)).success(function(response) {
      getAll();
      $scope.dateSave = "";
      $scope.moneySave = "";
      console.log('Success Insert');
    }).finally(function() {
      $scope.buttonDisabled = false;
    });
  };

  function getAll() {
    $http.get("http://localhost/mymoney/deposit.php")
      .then(function(response) {
        $scope.listDeposit = response.data.records;
      });
  };

  function conv_date(tgl) {
    return $filter('date')(tgl, 'yyyy-MM-dd');
  };
});

为什么当我单击addMoney函数两次时,我一次得到2个结果

Result when I click Save

0 个答案:

没有答案