app.config(['$routeProvider',"$httpProvider", "$locationProvider",'config', function ($routeProvider, $httpProvider, $locationProvider, config) { var rootPath = config.rootPath; var resolve = { delay: ['auth',function(auth){ return auth.get_bind(); }] }; var makeRoute = function(path, ctrl){ return { templateUrl: rootPath + path, controller: ctrl, resolve: resolve } } //$locationProvider.html5Mode(true); $routeProvider .when('/login', { templateUrl: rootPath + 'login.html', controller: 'LoginController' }) .when('/reg', { templateUrl: rootPath + 'reg.html', controller: 'RegController' }) .when('/activites', makeRoute('activities.html', 'ActivityController')) .when('/issues/:id', makeRoute('issue_detail.html', 'IssueController')) .when('/project_discussion/:id', makeRoute('project_discussion.html', 'DiscussionController')) .when('/homework/:id', makeRoute('homework_detail.html', 'HomeworkController')) .when('/course_notice/:id', makeRoute('course_notice.html', 'CourseNoticeController')) .when('/course_discussion/:id', makeRoute('course_discussion.html', 'DiscussionController')) .when('/journal_for_message/:id', makeRoute('jour_message_detail.html', 'JournalsController')) .when('/blog_comment/:id', makeRoute('blog_detail.html', 'BlogController')) .when('/class', makeRoute('class.html', 'ClassController')) .when('/new_class', makeRoute('new_class.html', 'NewClassController')) .when('/class_list', makeRoute('class_list.html', 'ClassListController')) .when('/myresource', makeRoute('myresource.html', 'MyResourceController')) .when('/invite_code', makeRoute('invite_code.html', 'InviteCodeController')) .when('/send_class_list', makeRoute('send_class_list.html', 'SendClassListController')) .otherwise({ redirectTo: '/activites' }); //监听异步请求,实现加载中显隐标记 $httpProvider.interceptors.push(['$q', '$rootScope', function ($q, $rootScope) { if ($rootScope.activeCalls == undefined) { $rootScope.activeCalls = 0; } return { request: function (config) { $rootScope.activeCalls += 1; return config; }, requestError: function (rejection) { $rootScope.activeCalls -= 1; return rejection; }, response: function (response) { $rootScope.activeCalls -= 1; return response; }, responseError: function (rejection) { $rootScope.activeCalls -= 1; return rejection; } }; }]); }]);