search

Home  >  Q&A  >  body text

angular.js - How does $http in angular filter the data obtained after a successful request?

As shown in the picture. The data actually returned to me by the backend is in the second layer of data.
How should I do a layer of data processing globally? Where is the best place to do it?

高洛峰高洛峰2873 days ago609

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-15 17:01:10

    angular.module('my', [])
            .config(function ($httpProvider) {
                $httpProvider.interceptors.push(function () {
                    return {
                        response: function (response) {
                            if (200 === response.data.code) {
                                response.data = response.data.data;
                            }
                            return response;
                        }
                    }
                });
            })

    reply
    0
  • Cancelreply