$resource callback (error and success)

前端 未结 3 932
梦谈多话
梦谈多话 2020-12-02 20:16

I´m using AngularJS 1.1.3 to use the new $resource with promises...

How can I get the callback from that? I tried the same way I did with $http :

$re         


        
3条回答
  •  猫巷女王i
    2020-12-02 20:49

    var MyResource = $resource("/my-end-point/:action", {}, {
        getSomeStuff: { method:"GET", params: { action:"get-some-stuff" }, isArray: true },
        getSingleThing: { method:"GET", params: { action:"get-single-thing" }, isArray: false }
    });
    
    function MyController(MyResource) {
        var itemList = MyResource.getSomeStuff({}, function success() {}, function err() {});
        // will call: /my-end-point/get-some-stuff
        // will be array. each object is resource's instance
        var item = MyResource.getSingleThing({id:123}, function success() {}, function err() {});
        // will call: /my-end-point/get-single-thing?id=123
        // will be object. an instance of resource
    }
    

    Also check out the example in docs: ngResource

提交回复
热议问题