Why does angular $resource add extra objects ($promise, $resolve…) to my data response?

前端 未结 5 832
感情败类
感情败类 2021-01-17 08:38

I return a resource with a URL

    $resource(\"http://foo.com/bar.json\").get().
         $promise.then(function(data){ $scope.result = data}, 
                     


        
5条回答
  •  粉色の甜心
    2021-01-17 09:08

    If you look at the angular source here:

    https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js#L505

    There is a toJSON method on the Resource prototype chain that will accomplish this for you.

    For example:

    $resource("http://foo.com/bar.json").get(function(res) {
        $scope.result = res.toJSON();
    });
    

提交回复
热议问题