AngularJS Save Browse History

I'm trying to solve a problem. I want that when a perform an action or function in the controller to be saved in the brose history. For example, I want to do this:

  • Type something in a textbox.
  • Click a link to call a function that will set the string I typed to a variable in $scope and save it at the browser history.
  • Do the same as the previous step with a different value.
  • If I click the "back" button from the browser, I want to display the first value I entered.

I have a very simple example of what I want but I don't know what do I have to add to be able to use the "back" and "forward" button from the browser.

http://jsfiddle.net/XMFua/

Thank you very much in advance!

You should use the $location service to set the URL. I don't know how to make it work on jsFiddle, however the following should work:

http://jsfiddle.net/marcenuc/BSDxG/