2

I made a keyPad popUp that change values in some variables in the scope. I want to revert any change made to those variables but when the popUp close, the changes are not made to those values that appear on the current view without refreshing the view.

Changing the values part in the popUp works flawlessly and in real time.

I tried to put the root of those variables in a temporary variable and the make the switch when the user cancel. To scope values are reverted, but the view is not updated.

var inventoryLineTemp = $scope.inventoryLine;
var updateQuantityPopup = $ionicPopup.show({
  templateUrl: 'templates/popUps/quantityPopUp.html',
  title: "Quantité",
  scope: $scope,
  buttons: [
    { text: 'Cancel',
      onTap: function(e) {
        $scope.inventoryLine = inventoryLineTemp;
      }
    }...
leseulsteve
  • 335
  • 3
  • 14

2 Answers2

6

You can't do like this var inventoryLineTemp = $scope.inventoryLine; Because they reference to the same object.

Use angular.copy instead:

var inventoryLineTemp = angular.copy($scope.inventoryLine);

Toan Nguyen
  • 11,263
  • 5
  • 43
  • 59
1

angular copy can also be used as follows

angular.copy(Source, Dest);

This worked for me when I was not getting values returned correctly by the copy

See Documentation here

Lord Darth Vader
  • 1,895
  • 1
  • 17
  • 26