angularJs实现自定义404页面及倒计时自动化跳转页面经常是我们业务需求
# html 页面
<h3>
页面未找到
</h3>
<p>找不到您要查找的页面</p>
{{ data.result.countdownTime }}s 后自动跳转到导航页
<p>
<a href="/">返回导航页</a>
</p>
angular.module("app").controller("errorPageCtrl", [
"$scope",
"$location",
function ($scope, $location) {
$scope.init = () => {
$scope.data = {
result: {
countdownTime: 5,
}
};
$scope.countdown = setInterval(() => {
$scope.data.result.countdownTime--;
$scope.$digest();
}, 1000);
setTimeout(() => {
clearInterval($scope.countdown);
$scope.$apply(() => {
$location.path("/")
});
}, 5000);
};
$scope.init();
}]);
angular.module("app").config((
$routeProvider,
$locationProvider) => {
// 常量 html文件路径
const templateUrl = "/xxx/xxx/templates";
$routeProvider
.when("/", {
controller: "xxxCtrl",
templateUrl: `${templateUrl}/xxx.html`
}
.otherwise({
controller: "errorPageCtrl",
templateUrl: `${templateUrl}/404.html`
});
});