gpt4 book ai didi

加载 View 时angularjs清除历史记录

转载 作者:行者123 更新时间:2023-12-04 17:10:13 35 4
gpt4 key购买 nike

有没有办法在通过 routeProvider 加载特定 View 时清除 Angular JS 存储的历史记录? ?

我正在使用 Angular 创建一个公共(public)安装,并且历史会积累很多,所以我想在加载主页时清除它。

最佳答案

在 Controller 中,我添加了一个更改 View 的函数:

$scope.changeView = function(view) {
$location.path(view);
$location.replace();
}

然后在 View 中我添加了一个 ng-click 来调用这个函数:
<div ng-click="changeView('/app/new_view')">

从 Angular 文档 $location.replace() 方法用于替换历史堆栈中的最顶层 View ,而不是添加新 View 。

There is a special replace method which can be used to tell the $location service that the next time the $location service is synced with the browser, the last history record should be replaced instead of creating a new one.



引用:
https://docs.angularjs.org/guide/ $位置

关于加载 View 时angularjs清除历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19069164/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com