Code from O'Reilly AngularJS book