如何在不刷新angularjs的情况下返回上一页? [英] How to go back to previous page without refreshing in angularjs?

查看:283
本文介绍了如何在不刷新angularjs的情况下返回上一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个内置了路由的AngularJS应用程序.它可以正常工作,并且一切正常. 我有2个控制器. 在第一个控制器中,当我单击按钮时,我有一个按钮,第二个控制器将运行.

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.

当我尝试返回或history.back()时,第一个控制器再次执行.

when i try to go back or history.back() the 1st controller is again executing.

如何预防?

推荐答案

如果您将控制器写为特定于页面,则只要将页面从一个页面重定向到另一页面,angularjs将始终执行控制器.

angularjs will always execute controllers when ever page is get redirected from one page to another page if you written controller as page specific.

如果您的应用程序是SPA,则可以在声明ng-view之前通过指定一个控制器进行重写(这不是一个好习惯).

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.

这篇关于如何在不刷新angularjs的情况下返回上一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆