问题
I currently have an AngularJS application with routing built in. It works and everything is ok. where i have 2 controller. in first controller i have a button when i click button 2nd controller will run.
when i try to go back or history.back()
the 1st controller is again executing.
how to prevent it?
回答1:
angularjs will always execute controllers when ever page is get redirected from one page to another page if you written controller as page specific.
If your application is SPA then you can rewrite by specifying a controller before declaring ng-view (its not a good practice).as
<div ng-controller="controller as cont">
<div ng-view>
</div>
</div>
now it will hold all your data until the application get closed.but, you should aware of cache.
来源:https://stackoverflow.com/questions/27268630/how-to-go-back-to-previous-page-without-refreshing-in-angularjs