0

I have a tree view. A user can select a node, then edit configuration of that node. I would like a way to detect whether this has changed at all from the original.

All examples I've seen of $watch happens on a scope level and don't allow me to see when a model has changed. How can I setup a watch (or something similar) that will tell me which object was changed so that I can do something like

$scope.itemChanged = function(item) {
  item.hasChanged = angular.equals(item, item.original);
}

I have tried deep watch examples like in this answer but they tell me only that the entire tree has changed, rather than which node. e.g.

$scope.$watch('tree', function (oldValue, newValue, scope) {
    console.log("changed", oldValue, newValue, scope);
}, true);
4
  • have you considered binding a change on the inputs the user can manipulate? Commented Mar 10, 2015 at 16:08
  • @Sphaso That was my first thought, but I also allow users to add nodes and to move nodes which would happen outside of the "form" so ideally I'd like to monitor all changes Commented Mar 10, 2015 at 16:09
  • What would you like to do once a node changes \ gets added etc.? Commented Mar 10, 2015 at 16:09
  • You can do watch a function $watch(function(){ return changedNode }, function(newVal){ }), but I would recommend capturing the changes in ng-change of inputs, rather than with a deep-watch Commented Mar 10, 2015 at 16:09

1 Answer 1

1

I have not done much angularjs but your question intrigued me so I think this post may help you angularjs treeview. The example has what I think you're looking for because it returns the .selectNodeHead that you can manipulate.

&(c.angularTreeview?(a.$watch(e,function(m,b){g.empty().html($compile(k)(a))},!1),a.selectNodeHead=a.selectNodeHead||function(a,b){b.stopPropagation&&b.stopPropagation()

Keep coding. Cheers

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.