加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 在离子下调试角度ui-router

发布时间:2020-12-17 07:09:29 所属栏目:安全 来源:网络整理
导读:我对 Angularjs和Ionic都很陌生,我试图围绕基于状态的路由扭曲.最大的障碍是,如果没有合适的方式来调试正在发生的事情,似乎很难钻进. 有一些help for debugging angularjs ui-routing in this question and answer – 但是这个例子只适用于AngularJS而不是Io
我对 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();
    }
  });  
})

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

解决方法

在这里,您只需一次运行方法调用即可将 AngularJS logging service注入您的Ionic项目:

angular.module('starter',['ionic','starter.controllers','starter.services'])
    .run(['$rootScope','$log','$ionicPlatform',function ($rootScope,$log,$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();
            }
        });

        // Debug stuff...
        $rootScope.$on('$stateChangeStart',function (event,toState,toParams,fromState,fromParams) {
            $log.debug('$stateChangeStart to ' + toState.name + '- fired when the transition begins. toState,toParams : n',toParams);
        });
        $rootScope.$on('$stateChangeError',fromParams,error) {
            $log.debug('$stateChangeError - fired when an error occurs during transition.');
            $log.debug(arguments);
        });
        $rootScope.$on('$stateChangeSuccess',fromParams) {
            $log.debug('$stateChangeSuccess to ' + toState.name + '- fired once the state transition is complete.');
        });
        // $rootScope.$on('$viewContentLoading',function(event,viewConfig){
        //   // runs on individual scopes,so putting it in "run" doesn't work.
        //   $log.debug('$viewContentLoading - view begins loading - dom not rendered',viewConfig);
        // });
        $rootScope.$on('$viewContentLoaded',function (event) {
            $log.debug('$viewContentLoaded - fired after dom rendered',event);
        });
        $rootScope.$on('$stateNotFound',unfoundState,fromParams) {
            $log.debug('$stateNotFound ' + unfoundState.name + '  - fired when a state cannot be found by its name.');
            $log.debug(unfoundState,fromParams);
        });
    }])

对于生产,您可以在配置块中禁用调试:

.config(function($logProvider){
    $logProvider.debugEnabled(false);
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读