我對Angular非常非常陌生,所以我想先就此問題表示歉意。使用Angular重定向到另一個頁面
我有這個發送POST請求的Angular腳本,並在失敗部分我想重定向用戶到另一個頁面。 這是網站的結構
-login夾
JS文件夾
controllers.js
的login.html
login.css
-index.html
我在controllers.js中的Angular代碼ID。我使用login.html中的代碼。我需要將用戶從login.html重定向到index.html。這不幸的是不起作用,當它進入代碼的錯誤部分時,它不會重定向用戶。
下面是代碼:
var app = angular.module('WebApp', []);
app.controller('myCtrl', function($scope, $http, $location) {
$scope.login = function($location){
$scope.incorrectPass = false;
$http.post('service link', {'email': $scope.username, 'password': $scope.password, 'UUID': 'dknasklaxcaosdhdajkshnjk', 'platform': 1})
.success(function(data, status, headers, config) {
alert("request success");
})
.error(function(data, status) {
$scope.$apply(function() { $location.path("/index.html"); });
});
}
});
如果你只使用Javascript'location.href'來重定向你的頁面,如果它無法加載請求,我想這會返回你想要做的! :) –
我希望在您的routeProvider或stateProvide你有路由到index.html。它從來沒有像這樣工作。你應該有路由到.html頁面 –
你有沒有看到任何錯誤?並配置好你的路線提供者? –