Skip to content

Instantly share code, notes, and snippets.

@CLOUGH
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CLOUGH/294a7e64aabc12372e23 to your computer and use it in GitHub Desktop.
Save CLOUGH/294a7e64aabc12372e23 to your computer and use it in GitHub Desktop.
Allow angular to watch nested object properties in array
$scope.chartBuilder = {
charts: [{
name: 'Gauge Chart',
type: 'gauge',
description: '',
title: '',
series: [{
resultQueryType: "",
resultQueryID: 0,
resultQueryFactID: 0,
}],
}, ]
};
// watch the chart series data for updates and make the necessary updates
$scope.$watchCollection('chartBuilder.charts', function(newCollection, oldCollection, scope) {
for (var i = 0; i < newCollection.length; i++) {
var expression = 'chartBuilder.charts['+i+'].series'
$scope.$watch(expression, function(newValue, oldValue, scope) {
console.log('Series Updated', newValue, oldValue);
}, true);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment