【问题标题】:$ionicModal forces route change$ionicModal 强制改变路线
【发布时间】:2016-11-11 15:54:59
【问题描述】:

我的$ionicModals 有点问题。每次我打开一个模式时,它都会强制一条空路线导致$urlRouterProvider.otherwise('/login'); 发生。如果我从我的配置中取出$urlRouterProvider,它工作正常——但是我的应用程序只是启动到一个空白屏幕。有谁知道是什么导致了这个问题?我在FeedController 中非常标准地称呼离子模态:

$ionicModal.fromTemplateUrl('templates/views/view.html', {
  scope: $scope,
  animation: 'slide-in-up'
}).then(function(modal) {
  $scope.modal = modal;
});

$scope.modal.show().then(function() {
  // Blah
});

我的配置如下所示:

$stateProvider
  .state('login', {
    url: '/login',
    templateUrl: 'templates/login.html',
    controller: 'LoginController',
    resolve: {
      'currentAuth': function(Auth) {
        return Auth.checkAuth().$waitForAuth();
      },
      'clearCache': function($ionicHistory) {
        return $ionicHistory.clearCache();
      }
    }
  })
  .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/main.html',
    controller: 'SideMenuController',
    resolve: {
      'currentAuth': function(Auth) {
        return Auth.checkAuth().$waitForAuth();
      }
    }
  })
  .state('app.feed', {
    url: '/feed',
    views: {
      'viewContent': {
        templateUrl: 'templates/views/feed.html',
        controller: 'FeedController',
        resolve: {
          'currentAuth': function(Auth) {
            return Auth.checkAuth().$requireAuth();
          },
          'clearCache': function($ionicHistory) {
            return $ionicHistory.clearCache();
          }
        }
      }
    });

  $urlRouterProvider.otherwise('/login');
});

我还应该提到我正在解决在状态加载之前检查 AngularFire 身份验证。我正在收听$rootScope 以查看是否有$stateChangeError,然后这会将用户重定向到登录屏幕,但这似乎不是问题,因此删除了$urlRouterProvider 行:

$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
  if (error === 'AUTH_REQUIRED') {
    $state.go('login');
  }
});

我还清除了FeedControllerLoginController 解析上的缓存。有没有人遇到过 $ionicModals 的这个问题?如果您能提供帮助,请告诉我。非常感谢。

【问题讨论】:

    标签: angularjs ionic-framework firebase angularfire firebase-authentication


    【解决方案1】:

    只是想在这里为其他遇到此问题的人发帖。我想出了解决方案。它是由 <a> 元素上的哈希 href="#" 引起的,导致路由更改。我猜$urlRouterProvider 在这种情况下看到了一条空白路线?

    【讨论】:

    • 谢谢!你刚刚把我的头从墙上救了下来。 :)
    【解决方案2】:

    我会将函数包装在 try catch 块中,您可以进行一些额外的错误检查以提供更多信息。

    此外,您假设 $ionicModal.fromTemplateUrl 已立即解决,因为您正在调用 $scope.modal.show() 而没有确保您确实有一个模式。

    $ionicModal.fromTemplateUrl('templates/views/view.html', {
      scope: $scope,
      animation: 'slide-in-up'
    }).then(function(modal) {
      $scope.modal = modal;
    
       return modal.show();
    
    }, function(_error) {
       console.log(_error)
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多