这段angularjs最佳实践的代码看不太懂

在angular最佳实践的ppt上看见这段代码:
http://trochette.github.io/Angular-Design-Patterns-Best-Practices/#/configuring_httpproviders

angular.module('notes',[])
        .config(["$httpProvider",
            function ($httpProvider) {

                var httpStatusCodeInterceptorFactory = function ($q) {


                    function onSuccess(response){
                        if("success_condition"){
                            return response.data;
                        }else{
                            //Show your global error dialog
                            $q.reject(response.data);//Very important to reject the error
                        }
                    };


                    function onError(response){
                        //Show your global error dialog
                        $q.reject(response);//Very important to reject the error
                    };



                    return function (promise) {
                        return promise.then(onSuccess,onError);
                    };
                };

                //Activate your interceptor
                $httpProvider.responseInterceptors.push(httpStatusCodeInterceptorFactory);
              }])

config里面的代码看不太懂,是不是之前老版本的函数式写法?
要是改成现在的写法怎么写呢?

阅读 3.3k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题