javascript - How to know which data has been changed in an array? -


i'm trying data has been changed in array. use case first time data fetch ajax , show within row , fetch new data using $http every 5 second. need know if new data same old one. if yes value has changed i've update background color..

what i've tried

var app = angular.module('app', []);      app.controller('listingcontroller', function($scope, $http, $timeout){          $scope.listings;          setinterval(function(){              $http.get('_includes/ajax.php?req=get').                 success(function(data, status, headers, config) {                   $scope.listings = data;                   console.log(data);                 }).                 error(function(data, status, headers, config) {                   // log error             });           }, 5000);      });      app.controller('rentaldatecontroller', function($scope, $log){           console.log($scope.listings);          $scope.$watch('listings.third_column', function (third_column, oldvalue) {             //$log.info(third_column, $scope.listings.first_column);              console.log('being watched oldvalue:', oldvalue, 'newvalue:', third_column);           }, true);     }); 

my html

<body ng-app="app">     <div ng-controller="listingcontroller">       <table>         <tr>             <th>testing</th>             <th>pripse</th>         </tr>          <tr ng-repeat="row in listings" ng-controller="rentaldatecontroller">             <input type="text" ng-model="row.third_column">             <input type="text" ng-model="row.first_column">             <th>{{row.third_column}}</th>             <th>{{row.first_column}}</th>         </tr>      </table>     </div> </body> 

i think need use $watch it's not working.

you have angular two-way data binding should automatically update ng-repeat when model changes.

i suggest following 1) remove rentaldate controller first. 2) use $timeout, , on success of http use this

$scope.$apply(function(){   $scope.listing = data; }); 

if doesn't still automatically update, put array in object.

$scope.data = {} $scope.data.listings = putarrayhere(); 

this work because of this. read up. :d

https://github.com/angular/angular.js/wiki/understanding-scopes#javascript-prototypal-inheritance


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -