提问人:Rvdux 提问时间:11/4/2023 最后编辑:ggorlenRvdux 更新时间:11/4/2023 访问量:27
$timeout函数在 if 中的条件后不起作用
$timeout function not working after a condition in if
问:
对不起,这是一个愚蠢的问题,我在 AngularJS 上很新,仍在学习它,所以我在这里的问题是 $timeout 函数,它在第一个“window.location.href”语句之后不起作用,我无法弄清楚这个问题。但是,如果我把它放在else语句中,它就可以工作,但这不是我想要的。我希望在执行第一个 URL 时,5 秒后执行第二个 URL。
angular.module('Route').controller('LoginController', ['$scope', 'LoginService', '$timeout',
function ($scope, LoginService, $timeout) {
$scope.credentials = {
Login: '',
Password: ''
};
$scope.login = function () {
LoginService.login($scope.credentials)
.then(function (response) {
console.log("Response data: ", response.data);
if (response.data.length > 0) {
window.location.href = "http://localhost:8080/Views/home.html#!/employee";
$timeout(function () {
window.location.href="http://localhost:8080"; }, 5000);
} else {
alert("Vérifier vos données s'il vous plâit");
$scope.credentials.Password = '';
}
})
.catch(function (error) {
console.error("Error", error);
});
};
}]);
答: 暂无答案
评论
window.location.href = ...