How to go back to previous page without refreshing in angularjs?

眉间皱痕 提交于 2019-12-11 10:35:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!