2

I have stripped my problem down to the most minimal form, as seen here: http://jsfiddle.net/ejubN/

I basically want to be able to load a large JSON object into $scope.b that gets rendered. And if any of the elements in @scope.b are changed, updated, or if a new one is created, then 'contenteditable' should be triggered to save that back to my rails application via a POST.

1 Answer 1

2

This fiddle shows some code that will call a listener whenever $scope.b changes: http://jsfiddle.net/Gloopy/SQuVy/

I may have stripped the example down too far but I'm assuming you don't need a directive and you were basing this off a sample from the AngularJS docs. Also I changed $scope.b to contain javascript objects instead of primatives due to binding issues with ng-repeat described here (which will hopefully be a better test since you're loading a large JSON object).

You should be able to do your post using the $http service though posting every time the listener fires is probably not ideal. Others may have better suggestions on when to actually do your saves but hopefully this helps!

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

2 Comments

Thanks for your response. I understand why you used $watch instead, but if I change your example to bind 'a.value' to a contenteditable div it stops working. I did base it off the docs you linked to and part of the reason why I based it off that was because they had a contenteditable directive.
See if this fiddle is more what you are looking for jsfiddle.net/yBA6c/1. My fiddle didn't have the contenteditable directive which is why it didn't work when you modified it. I think your original example would have worked if you weren't binding to primatives.

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.