Reputation: 213
Is it possible to use $watch in order to create an undo functionality which I could use to undo any last change in the view? For example, I have multiple input fields, ng-includes on demand etc - what would be the easiest and most efficient way of implementing Undo functionality?
I was thinking about pushing any change on the view to an array, and in case of undoing() simply deleting the last item from that array and serving the array again, though not sure if there is another, better way of doing that in angular. Any tips?
Upvotes: 1
Views: 859
Reputation: 1033
You could use the LazyJsonUndoRedo:
https://github.com/azazdeaz/LazyJsonUndoRedo
http://dailyjs.com/2014/07/18/lazy-json-undo/
From the readme:
A 'drop in' history handler with automatic undo/redo functionality for nested javascript objects, using ES6 Object.observe() or Polymer shim.
Upvotes: 1