Angular.js从一个抽象状态子项重定向到另一个

时间:2014-11-03 06:59:51

标签: javascript angularjs ionic-framework

我尝试使用Angular.js以Laravel作为后端来实现登录。我使用抽象状态来处理布局。有两种抽象状态:1表示公共页面,1表示管理页面。问题是当我登录时,当我使用$state.go('admin.dash')$window.location.href = '#/admin/dash'时,它会将我重定向到页面,但侧栏未加载。它仅在我直接访问页面或在浏览器上刷新整页时加载。

这是我的loginController的样子:

(function(){

    angular.module('starter.controllers')
    .controller('LoginController', ['$scope', 'UserService', '$state', '$window', LoginController]);
    function LoginController($scope, UserService, $state, $window){
        var me = this;

        me.loginUser = function(user){

            UserService.login(user).then(function(data){
                $window.location.href = ('#/admin/dash'); //also tried $state.go
            });

        };

    };
})();

以下是状态的应用配置:

.config(function($stateProvider, $urlRouterProvider) {

    .state('home', {
      url: "/home",
      abstract: true,
      templateUrl: "templates/layouts/tabs.html"
    })
    .state('home.login', {
      url: '/login',
      views: {
        'home-login': {
          templateUrl: 'templates/tab-login.html',
          controller: 'LoginController'
        }
      }
    })
    .state('admin', {
      url: "/admin",
      abstract: true,
      templateUrl: "templates/layouts/admin-menu.html"
    })
    .state('admin.dash', {
      url: '/dash',
      views: {
        'menuContent': {
          templateUrl: 'templates/admin/dash.html'
        }
      }
    });

所以基本上我试图从home状态重定向到admin状态。当我检查chrome dev工具时,HTML实际上已加载,但我不知道为什么侧边栏不会出现:

enter image description here

这是我使用$state.go$window.location.href时的屏幕截图:

enter image description here

以下是我直接访问时的样子:

enter image description here

0 个答案:

没有答案