如何角应用程序句柄刷新页面,我们可以使用$历史上加载指令 [英] How does angular application handle refresh page and could we use $history on loading directives

查看:195
本文介绍了如何角应用程序句柄刷新页面,我们可以使用$历史上加载指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是两个问题。


  1. 如何角应用程序处理刷新页面,B从我听到/ C,$ rootScope destroy()方法的刷新和应用程序得到重新运行并重新配置-ed,我在想,如果有一个优雅办法preserve的$ rootScope无需$ rootScope变量存储为一个字符串到存储。


  2. 如果我上加载加载页面上的模态指令的模板,是有可能配置历史不能导航,但恢复开放的模式。并且由于验证和这样的,我不认为这是可能使用的href来实现同样的功能。



解决方案

如果您的URL与映射 $ routeProvider ,您可以重新加载控制器调用 $ route.reload()。这刷新页面,而不破坏$ rootScope。结果
我已创建一个plunker显示此。该控制器计算多少次页面已被重新加载。

So two questions.

  1. How does angular applications handle refresh page, b/c from what I heard, $rootScope destroy() on refresh and application gets re-run and re-config -ed, and I was wondering if there's an elegant way to preserve the $rootScope without having to store $rootScope variables as a string into a storage.

  2. If I load a template on a directive that loads a modal on the page, is it possible to configure history to not navigate but to revert the open modal. and due to validations and such, I do not think it is possible to implement same function using href.

解决方案

If your url's are mapped with the $routeProvider, you can reload a controller invoking $route.reload(). This refresh the page without destroy the $rootScope.
I have create a plunker to show this. The controller counts how many times the page has been reloaded.

这篇关于如何角应用程序句柄刷新页面,我们可以使用$历史上加载指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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