Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 发生重定向时,仍显示旧页面_Angularjs - Fatal编程技术网

Angularjs 发生重定向时,仍显示旧页面

Angularjs 发生重定向时,仍显示旧页面,angularjs,Angularjs,在我的控制器中,我有这样一个重定向,从登录页面重定向到索引页面 var loginApp = angular.module('angularRestfulAuth', ['ngCookies', 'ngStorage', 'ngRoute', 'angular-loading-bar']); loginApp .controller('HomeCtrl', ['$rootScope', '$scope', '$location','$cookies','$window',

在我的控制器中,我有这样一个重定向,从登录页面重定向到索引页面

var loginApp = angular.module('angularRestfulAuth', ['ngCookies', 'ngStorage',
    'ngRoute',
    'angular-loading-bar']);
loginApp
    .controller('HomeCtrl', ['$rootScope', '$scope', '$location','$cookies','$window',  'Main', function($rootScope, $scope, $location,$cookies, $window,Main) {

        $scope.signin = function() {
            var formData = {
                username: $scope.username,
                password: $scope.password
            }

            Main.signin(formData, function(res) {
                if (res.type == false) {
                    alert(res.data) ;  
                } else {
                  //location.href='/index'; 
                  $window.location.assign('/index');
                }
            }, function() {
                $rootScope.error = 'Failed to signin';
            })
        };
app.js看起来像

angular.module('angularRestfulAuth', [
    'ngStorage',
    'ngRoute',
    'angular-loading-bar'
])
.config(['$routeProvider', '$httpProvider','$cookies','$locationProvider', function ($routeProvider, $httpProvider,$cookies,$locationProvider) {

    $routeProvider.     
        when('/index', {
           templateUrl: 'app/partials/index.html',
                controller: 'myController'

        }).
        when('/signin', {
            templateUrl: 'app/partials/signin.html',
            controller: 'HomeCtrl'
        }).
        otherwise({
            redirectTo: '/'
        });
         $locationProvider.html5Mode(true);
如果我使用,
location.href='/index'

那么

http://localhost:5000/index

错误:无法获取/索引

如果我使用,
$location.url('/index')

那么

http://localhost:5000/#/index


但是仍然显示登录页面,而不是索引页面。

尝试使用
$location.path()
我想知道您的两个模板URL是不同的,即使它们是相同的place@Hadi:试过了。。然后
http://localhost:5000/#/index
但仍然显示当前登录页面。@我刚刚更改了模板url以测试它。但现在我指的是
当(“/index”
仅是您的模板URl正确时,因为我可以看到“/index”和“/sign”的两个不同集合…其中一个有应用程序
var loginApp = angular.module('angularRestfulAuth', ['ngCookies', 'ngStorage',
    'ngRoute',
    'angular-loading-bar']);
loginApp
    .controller('HomeCtrl', ['$rootScope', '$scope', '$location','$cookies','$window',  'Main', function($rootScope, $scope, $location,$cookies, $window,Main) {

        $scope.signin = function() {
            var formData = {
                username: $scope.username,
                password: $scope.password
            }

            Main.signin(formData, function(res) {
                if (res.type == false) {
                    alert(res.data) ;  
                } else {
                  //location.href='/index'; 
                  $window.location.assign('/index');
                }
            }, function() {
                $rootScope.error = 'Failed to signin';
            })
        };