AngularJS使用拦截器实现的loading功能完整实例
本文实例讲述了AngularJS使用拦截器实现的loading功能。分享给大家供大家参考,具体如下:
.mask-loading.loading-icon{ -webkit-animation:rotate1slinearinfinite; -o-animation:rotate1slinearinfinite; animation:rotate1slinearinfinite; position:absolute; top:50%; left:50%; width:30px; height:30px; margin:-20px00-20px; border-width:5px; border-style:solid; border-color:#37c3aa#37c3aa#fff#fff; opacity:.9; border-radius:20px; } @-webkit-keyframesrotate{ 0%{-webkit-transform:rotate(0)} 100%{-webkit-transform:rotate(360deg)} } @keyframesrotate{ 0%{transform:rotate(0)} 100%{transform:rotate(360deg)} } .mask-loading{ position:fixed; top:0; right:0; bottom:0; left:0; background:00; z-index:9999; } varmyApp=angular.module('myApp',['ui.router','ngAnimate']); myApp.config(["$stateProvider","$httpProvider",'$urlRouterProvider',function($stateProvider,$httpProvider,$urlRouterProvider){ $stateProvider .state('a',{ url:'/a', templateUrl:"loadpath/a.html", controller:"aController" }) .state('b',{ url:'/b', templateUrl:"loadpath/b.html", controller:"bController" }); $urlRouterProvider.otherwise('/'); $httpProvider.interceptors.push('myInterceptor'); }]); //loading myApp.factory('myInterceptor',["$rootScope",function($rootScope){ vartimestampMarker={ request:function(config){ $rootScope.loading=true; returnconfig; }, response:function(response){ $rootScope.loading=false; returnresponse; } }; returntimestampMarker; }]); myApp.controller('aController',function($scope){ $scope.page="a"; }); myApp.controller('bController',function($scope){ $scope.page="b"; }); index