1

我正在尝试对一个值执行更新,但是,分配给它的新值绑定到范围值但不会更改,当我编辑时,它会保存原始empty
细分

$scope.showDepositUpdate = function(birthday) {
        $scope.depositValue="one";
        $scope.birthday = birthday;
        $scope.action = 'deposit';
        $scope.isAdd = false;
        $scope.showUpdateModal = true;
    };
$scope.updateDeposit = function() {
            $scope.birthday.Name = $scope.depositValue;
            StoreFactory.updateBirthday($scope.birthday);
            $scope.depositValue='';
            newValue =""
            $scope.showUpdateModal = false;

    };

scope.depositValue不会根据视图上的值更新它,它总是concat“”,这是我的观点

<form class="form-inline" ng-show="showUpdateModal">
            <h2 class="title">{{ action }} Birthday</h2>
            <div class="form-group">
                <input type="text" class="form-control"  ng-model="birthday.Name" placeholder="name" placeholder="Jane Doe">
            </div>
            <div class="form-group">
                <input type="text" class="form-control"  ng-model="depositvalue" placeholder="name" placeholder="deposit">
            </div>
            <button ng-click="updateDeposit()" class="btn btn-default btn-lg btn-rounded">Save</button>
  </form>

<tr ng-repeat="birthday in birthdays">
            <td>{{ birthday.Name }}</td>
            <td>{{ birthday.Date }}</td>
            <td> <button class="btn btn-info btn-sm btn-rounded" ng-click="showDepositUpdate(birthday)">deposit</button>
4

2 回答 2

1

在您的函数$scope.updateDeposit中,您将变量 depositValue 的值设置为“”。$scope.depositValue='';. 也许这是你的问题?

我做了一个片段来向你展示这一点。

看看是不是你想要的。

var $scope = {};

var myApp = angular.module('myApp', []);

var StoreFactory = {
  updateBirthday: function(){return true} // JUST A MOCKUP
};

myApp.controller('myCtrl', ['$scope',
  function($scope) {

    $scope.showDepositUpdate = function(birthday) {
      $scope.depositValue = "one";
      $scope.birthday = birthday;
      $scope.action = 'deposit';
      $scope.isAdd = false;
      $scope.showUpdateModal = true;
    };
    $scope.updateDeposit = function() {
      $scope.birthday.Name = $scope.depositValue;
      StoreFactory.updateBirthday($scope.birthday);
      $scope.depositValue = '';
      newValue = ""
      $scope.showUpdateModal = false;

    };

  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="myApp" ng-controller="myCtrl">

  <form class="form-inline" ng-show="showUpdateModal">
    <h2 class="title">{{ action }} Birthday</h2>
    <div class="form-group">
      <input type="text" class="form-control" ng-model="birthday.Name" placeholder="Jane Doe">
    </div>
    <div class="form-group">
      <input type="text" class="form-control" ng-model="depositvalue" placeholder="deposit">
    </div>
    <button ng-click="updateDeposit()" class="btn btn-default btn-lg btn-rounded">Save</button>
  </form>

  <tr ng-repeat="birthday in birthdays">
    <td>{{ birthday.Name }}</td>
    <td>{{ depositvalue }}</td>
    <td>
      <button class="btn btn-info btn-sm btn-rounded" ng-click="showDepositUpdate(birthday)">deposit</button>
    </td>
  </tr>

于 2015-10-15T15:15:12.857 回答
0

您是否尝试过您工厂中的值的 console.log() ?那里的价值是什么?

我曾经遇到过这样的问题,那是因为(提到你的问题)

$scope.birthday.Name

只是一个引用$scope.depositValue,所以你传递一个对在函数调用 ( $scope.depositValue = '') 之后发生了很大变化的函数的引用。很高兴知道StoreFactory.updateBirthday($scope.birthday);实际做了什么。

于 2015-10-15T15:16:46.190 回答