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

savokiss
  • 6.2k

在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里面的代码看不太懂,是不是之前老版本的函数式写法?
要是改成现在的写法怎么写呢?

回复
阅读 2.6k
1 个回答
✓ 已被采纳
宣传栏