Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AngularJS路由之ui-router(三)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

一、为ui-router添加进度条

在使用动态控制器或者ajax,添加数据的时候需要进度条提示

我们可以使用路由状态的事件添加全局进度条提示

$stateChangeStart: 当状态开始改变时触发

$stateChangesuccess: 当状态改变结束时触发

二、实例1,创建一个进度条指令

// Route State Load Spinner(used on page or content load)
MetronicApp.directive('ngSpinnerBar',['$rootScope','$state',function($rootScope,$statE) {
        return {
            link: function(scope,element,attrs) {
                // by defult hide the spinner bar
                element.addClass('hide'); // hide spinner bar by default

                // display the spinner bar whenever the route changes(the content part started loading)
                $rootScope.$on('$stateChangeStart',function() {
                    element.removeClass('hide'); // show spinner bar
                });

                // hide the spinner bar on rounte change success(after the content loaded)
                $rootScope.$on('$stateChangesuccess',function() {
                    element.addClass('hide'); // hide spinner bar
                    $('body').removeClass('page-on-load'); // remove page loading inDicator
                    Layout.setAngularJsSidebarMenuActiveLink('match',null,$statE); // activate SELEcted link in the sidebar menu
                   
                    // auto scorll to page top
                    setTimeout(function () {
                        App.scrollTop(); // scroll to the top on content load
                    },$rootScope.setTings.layout.pageAutoScrollOnLoad);     
                });

                // handle errors
                $rootScope.$on('$stateNotFound',function() {
                    element.addClass('hide'); // hide spinner bar
                });

                // handle errors
                $rootScope.$on('$stateChangeError',function() {
                    element.addClass('hide'); // hide spinner bar
                });
            }
        };
    }
])

更多:

AngularJS路由之ui-router(二)

AngularJS路由之ui-router(一)

大佬总结

以上是大佬教程为你收集整理的AngularJS路由之ui-router(三)全部内容,希望文章能够帮你解决AngularJS路由之ui-router(三)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。