fix($rootScope): remove history event handler when app is torn down

Remember the popstate and hashchange handler registered with window
when the application bootstraps, and remove it when the application
is torn down

Closes #9897
`off` should probably be used instead of the legacy `unbind`. Could also make it one line doing `jqLite(window).off('popstate hashchange', cacheStateAndFireUrlChange);`