我对Angularjs和Ionic还是很陌生,我想绕过基于状态的路由。最大的障碍是,如果没有一种体面的方法来调试正在发生的事情,似乎很难钻研。
在此问答中,对调试angularjs ui-routing有一些帮助 -但是该示例仅适用于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(); } }); })
谁能帮助我了解如何在此处注入调试代码?
多亏了乔治·斯托克特(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); }); }])