Identify object in angular js has changed

I have a base object that I get from the server and sent to the server. I allow my users to modify the internal object. I would like to determine if the backend object has changed from the savepoint.

How can I identify him?

For example: I have a module called

app.controller('PanelCtrl', function($scope, $http) {
$scope.action = "";
$scope.selectedItem = "";
    $scope.compoundItem = [];

...

I have an array of compound elements of objects. I would like to know if something has changed, is there a change in the primitives and is there in the composite element ...

+4
source share
2 answers

Edit: two scenarios 1) client verification (original message) 2) server verification (advanced based on comments)

1) check on client

. ,

: angular.equals() : / ( ). script ():

function Controller($scope) {
  $scope.master = {};

  $scope.update = function(user) {
    $scope.master = angular.copy(user);
  };

  $scope.reset = function() {
    $scope.user = angular.copy($scope.master);
  };

  $scope.isUnchanged = function(user) {
    return angular.equals(user, $scope.master);
  };
}

, , - , . ( ). isUchnaged , angular.equals()

Angular

. angular.copy(). , lo-dash . DeepClone()

2)

, ( ) , . , , - else "".

, . , / , "". MS SQL Server rowversion, .

, sucesfull UPDATE, , , ... .

:

:

  • Client (current) Version
  • .

NHiberante ( )

+9

, , - $timeout(isDifferent,xtime)

:

isDifferent= - , .

xtime= is , , .

0

All Articles