0

Sorry I'm not sure how to ask this question but the code is pretty straight forward I think. I want to check if the data being returned from the DB has changed and if so update the scope. However when I do the compare it always comes back as different and does the update:

$scope.tickets = Ticket.tickets.query();

updateTickets = $interval(function(){
 var deferred = $q.defer();
 $scope.curTickets = $scope.tickets;
 deferred.resolve(Ticket.tickets.query());
 var promise = deferred.promise;

 promise.then(function(newTickets){
  $scope.newTickets = newTickets;
  if($scope.curTickets != $scope.newTickets){
    $scope.tickets = $scope.newTickets;
    console.log('newtickets!');
  } else {
    console.log('no newtickets');
  }
 });

},90000);

1 Answers1

0

As mentioned in https://stackoverflow.com/a/201471/3878940, there is no definite way of comparing the equality of 2 objects in JavaScript. So, you may need to look for an alternative approach to recursively compare the values of the response object by writing a custom method.

Community
  • 1
  • 1
Aditya Singh
  • 15,810
  • 15
  • 45
  • 67
  • Thanks, I found the .equals works but I had to change the way I was returning the object and use a function to handle the returned data: `Ticket.tickets.query({},function(data){ $scope.newTickets = data;` etc etc. – Ryan Stinn Apr 12 '16 at 17:32