angularjs - 在 ionic 下调试 Angular ui-router

标签 angularjs debugging ionic-framework ionic angular-ui-router

我对 Angularjs 和 Ionic 还很陌生,我正试图绕开基于状态的路由。最大的障碍是,如果没有合适的方式来调试正在发生的事情,似乎很难深入研究。

有一些help for debugging angularjs ui-routing in this question and answer - 但该示例仅适用于 AngularJS,而不适用于 Ionic,我正在努力弄清楚如何在 Ionic 中实现此解决方案。

在 AngularJS 中,调试代码会放在这里:

angular.module('MyModule').run(['$rootScope',function($rootScope){ // put the event handlers here }]);

但在 Ionic 中,相应的代码如下所示:
run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });  
})

谁能帮我理解如何在这里注入(inject)调试代码?

最佳答案

感谢 George Stocker 的评论我想到了。生成的代码如下所示:

angular.module('starter', [])
.run(['$rootScope',function($rootScope){ 

    $rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
          console.log('$stateChangeStart to '+toState.to+'- fired when the transition begins. toState,toParams : \n',toState, toParams);
        });
    $rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams, error){
          console.log('$stateChangeError - fired when an error occurs during transition.');
          console.log(arguments);
        });
    $rootScope.$on('$stateChangeSuccess',function(event, toState, toParams, fromState, fromParams){
          console.log('$stateChangeSuccess to '+toState.name+'- fired once the state transition is complete.');
        });
    $rootScope.$on('$viewContentLoaded',function(event){
          console.log('$viewContentLoaded - fired after dom rendered',event);
        });
    $rootScope.$on('$stateNotFound',function(event, unfoundState, fromState, fromParams){
          console.log('$stateNotFound '+unfoundState.to+'  - fired when a state cannot be found by its name.');
          console.log(unfoundState, fromState, fromParams);
        });
}])

关于angularjs - 在 ionic 下调试 Angular ui-router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34602257/

相关文章:

angular - 在 Angular/Ionic 中重定向到 401 后登录

javascript - ui.router 没有重新加载 Controller

datetime - 将 bootstrap-datetime 选择器与 AngularJS 结合使用

javascript - 无法从 Angular 中的模板调用表单提交方法

android - 如何设置 Eclipse 的构建配置以生成正确的、可调试的 NDK 应用程序?

java - 使用工厂模式时出现 NullPointerException

javascript - Angular 使用一个函数实现多个事件

使用单选按钮和 ng-repeat 进行 AngularJS 表单验证

visual-studio-2010 - 我们在 Visual Studio 2010 Express 中有 Quick Watch 吗?

ios - 在 IOS 上调试 Ionic 应用程序?