I want to synchronize data, therefore I have a data object containing the current state. When this is changed I would like to set an attribute on the object so that I can filter by this when syncing. The object structure is:
data = {
type1: [
{a:"a", b:"b"},...
]
type2: [
{c:"c", d:"d"},...
]
}
For example if data.type1[0].a = "test" would be done, I would like to add modified: true to the object so that it would be
{a:"test", b:"b", modified:true}
I have tried $watch(data, function(), true) but I can not find how I can see which object was changed and searching both given data objects would be a large overhead. $watchcollection (when just looking for adding/deleting) also does not give an index.
Is there any way to find out which object was changed? Or is there an other library which can do this well?
Thank you
EDIT:
I created a jsfiddle: https://jsfiddle.net/yfo8xwah/
$pristine
and$dirty
work for you? docs.angularjs.org/api/ng/type/form.FormController – Entremets$watch
gives younewVal
andoldVal
and you can compare both to find which one was changed. – Hentrich