我正在使用angularjs
,我希望当页面加载时,它只刷新一次,我尝试过:
<script>
app.cp.register('userProfileController', function ($window) {
debugger;
function reload() {
$window.location.reload();
}
reload();
});
但是这样页面就会无限次刷新,请问有什么问题吗?
最佳答案
当页面刷新时,所有内容都会被删除,并且您将重新注册 Controller 并执行 reload()
,所以是的,它会继续发生。
为了在页面刷新之间保留数据,您可以使用 ngStorage :
app.cp.register('userProfileController', function ($window, $localStorage) {
debugger;
function reload() {
$localStorage.hasReloaded = true;
$window.location.reload();
}
if (!$localStorage.hasReloaded) reload();
});
关于javascript - 在 angularjs 中仅重新加载页面一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38551809/