2015-04-28 24 views
0

我對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"); }); 
    }); 
    } 
}); 
+0

如果你只使用Javascript'location.href'來重定向你的頁面,如果它無法加載請求,我想這會返回你想要做的! :) –

+0

我希望在您的routeProvider或stateProvide你有路由到index.html。它從來沒有像這樣工作。你應該有路由到.html頁面 –

+0

你有沒有看到任何錯誤?並配置好你的路線提供者? –

回答

0

我在你routeProvider或stateProvide希望你能index.html的路線。它從來沒有像這樣工作。你應該有途徑爲.html頁面

.config(['$routeProvider', function ($routeProvider) { 
    $routeProvider 
    .when("/home", { 
     title: 'home', 
     templateUrl: 'index.html', 
     controller: 'HomeController as homeCtrl' 
    }) 
    .otherwise({ 
     redirectTo: '/login' 
    }); 

現在,如果你在你的登錄做

$location.path("/home"); 

/JS/controller.js文件,應當編制。

0

使用此代碼進行重定向 $ window.location.href ='/index.html';

相關問題