1

I'm trying to perform update on a value but ,the new value that am assigning to it bound to scope value but does not change ,when I edit ,it save with the original empty value
breakdown

$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;

    };

but scope.depositValue does not update it according to value on the view , it always concat to "", here is my view

<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>
Alvaro Silvino
  • 9,441
  • 12
  • 52
  • 80

2 Answers2

1

In your function $scope.updateDeposit you are stting up the value of the variable depositValue to "". $scope.depositValue='';. Maybe this is your problem?

I've done a snipet to show you that.

See if it is what you want.

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>
Bruno João
  • 5,105
  • 2
  • 21
  • 26
0

Did you try a console.log() of the value in your Factory? Whats the value there?

I once had such a problem and that was because (referred to your problem)

$scope.birthday.Name

is just a reference to $scope.depositValue and so you pass a reference to a function that is changed quite after function call ($scope.depositValue = ''). Would be good to know what StoreFactory.updateBirthday($scope.birthday); actually does.

David
  • 153
  • 7