AngularJs视图无法在Google Chrome上呈现。 (控制台没有错误)

时间:2015-12-04 08:37:00

标签: angularjs google-chrome views

我有一个角度应用程序已经运行了一段时间了,但突然在一些功能更新后它停止了谷歌浏览器的工作。 它基本上没有渲染任何HTML,我可以通过chrome检查器看到html在那里它只是没有渲染。 控制台中也没有错误。 我无能为力。 PS-它在Mozilla Firefox和IE上运行良好。 PPS-Im使用Chromium - 版本45.0.2454.85 Ubuntu 14.04(64位)      但是,我的同事在Google Chrome for Mac上分享了同样的问题。

此外,如果我在应用中的任何位置放置了console.log(),它会显示并且它会到达所有代码。 我还没有在控制器中测试过,除了正在使用的控制器(它是一个登录屏幕,所以我只是测试与它相关的所有资源。)

我的控制器在视图中运行:

'use strict'; 

app.controller('AuthCtrl', ['$scope', 'Authorization', '$activityIndicator',  '$timeout', function($scope, Authorization, $activityIndicator,  $timeout) {

    $scope.signin = function(user){
      $activityIndicator.startAnimating();
      console.log('login');
      Authorization.login(user);
    }

    $scope.signout = function(){
      $activityIndicator.startAnimating();
      Authorization.logout();
    }

}]);

HTML:

<div class="preloader text-center" ng-if="AILoading"><i class="fa fa-spinner fa-spin"></i></div>

<div class="login-page" >
    <div class="row">
        <div class="col-md-4 col-lg-4 col-md-offset-4 col-lg-offset-4 login-container" >
            <img src="images/logo.jpg" class="img-circle user-avatar" />
            <form role="form" ng-submit="signin(user)">

                <div class="form-content">
                    <div class="form-group">
                        <input type="text" class="form-control input-underline input-lg" id="" placeholder="Username"
                        ng-model="user.username">
                    </div>

                    <div class="form-group">
                        <input type="password" class="form-control input-underline input-lg" id="" placeholder="Password"
                        ng-model="user.password">
                    </div>
                </div>  
                <button type="submit" class="btn btn-primary btn-outline btn-lg btn-rounded">Login</button>

            </form>         
        </div>  
    </div>
</div>

涉及的服务:

'use strict';

app.service('Authorization', ['$http', '$cookies', '$location', '$activityIndicator', 'LOGIN', 'LOGOUT', 
    function($http,  $cookies, $location, $activityIndicator,  LOGIN, LOGOUT) {

    this.login = function(user){
       var postData = {
        'username' : user.username,
        'password' : user.password
       }

       $http.post(LOGIN,postData)
       .success(function(response, header){
            $cookies.put('djangotoken', response.token);
            $cookies.put('user', postData.username);
            $http.defaults.headers.common['Authorization'] = 'Token ' +  response.token;
            $location.path('/dashboard');
            $activityIndicator.stopAnimating();
          return true;
        })
        .error(function(response, status){
            console.log("Error in Login - " + status);
            $activityIndicator.stopAnimating();
          return false;
        });
    }

    this.logout = function(){
          $http.post(LOGOUT)
            .success(function(data, status, header, config){
                $cookies.remove('djangotoken');
                $cookies.remove('user');
                $location.path('/login');
                $activityIndicator.stopAnimating();
                return true;
            })
            .error(function(data, status, header, config){
                console.log("Error in Logging Out - "+status);
                $activityIndicator.stopAnimating();
                return false;
            }); 
    }


}]);

另外我认为这可能是路由问题。 (虽然最后一个无bug版本有相同的路由。)

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

    $urlRouterProvider.when('/dashboard', '/dashboard/ops-home');
    $urlRouterProvider.otherwise('/dashboard');

    $stateProvider
      .state('base', {
        abstract: true,
        url: '',
        templateUrl: 'views/base.html'
        })
        .state('/404', {
          url: '/404',
          parent: 'base',
          templateUrl: 'views/404.html'
        })
        .state('login', {
          url: '/login',
          parent: 'base',
          resolve: {
            location: [
                '$location', '$cookies'
                , function ($location, $cookies) {
                  if($cookies.get('djangotoken')){
                    console.log($cookies.get('djangotoken'));
                    $location.path('dashboard/ops-home');
                    console.log('resolve login');
                  }

            }]
          },
          templateUrl: 'views/login.html',
          controller: 'AuthCtrl'
        })
        .state('dashboard', {
          url: '/dashboard',
          parent: 'base',
          resolve: {
            location: [
                '$location', '$cookies'
                , function ($location, $cookies) {
                  if(!$cookies.get('djangotoken')){
                    console.log($cookies.get('djangotoken'));
                    $location.path('login');
                    console.log('resolve dashboard');
                  }

            }]
          },
          templateUrl: 'views/dashboard.html',
          controller: 'DashboardCtrl'
        })
        .state('ops-home', {
          url: '/ops-home',
          parent: 'dashboard',
          templateUrl: 'views/dashboard/ops-home.html'
        })
        .state('order-history', {
          url: '/history',
          parent: 'dashboard',
          templateUrl: 'views/dashboard/order-history.html',
          controller: 'OrderManagerCtrl'
        })
        .state('confirm-orders', {
            url: '/confirm-orders',
            parent: 'dashboard',
            templateUrl: 'views/dashboard/confirm-orders.html',
            controller: 'OrderManagerCtrl'
        })
        .state('new-orders', {
            url: '/new-orders',
            parent: 'dashboard',
            templateUrl: 'views/dashboard/new-orders.html',
            controller: 'OrderCtrl'

        })
        .state('update-orders', {
            url: '/update-orders',
            parent: 'dashboard',
            templateUrl: 'views/dashboard/update-orders.html',
            controller: 'OrderUpdateCtrl'
        })
        .state('receive', {
            url: '/receive',
            parent: 'dashboard',
            templateUrl: 'views/dashboard/receive.html',
            controller: 'OrderManagerCtrl'
        })
        .state('create-shipment', {
            url: '/create-shipment',
            parent: 'dashboard',
            templateUrl: 'views/dashboard/create-shipment.html',
            controller : 'ShipmentCtrl'
        })
        .state('assign-cp', {
          url: '/assign-partner',
            parent: 'dashboard',
            templateUrl: 'views/dashboard/assign-cp.html',
            controller : 'ShipmentCtrl'
        })
        .state('update-shipment', {
            url: '/update-shipment',
            parent: 'dashboard',
            templateUrl: 'views/dashboard/update-shipment.html',
            controller : 'ShipmentUpdateCtrl'
        })
        .state('documents',{
          url: '/download-documents',
          parent: 'dashboard',
          templateUrl: 'views/dashboard/documents.html',
          controller: 'DocumentCtrl'
        });
      });

1 个答案:

答案 0 :(得分:0)

我无法找到此问题背后的原因,但解决方案是在height:100%;标记中提供css width:100%;html,body规则。 我认为一些谷歌浏览器干扰了CSS。 怪异..