how to fix Expected response to contain an array but got an object ANgular js

前端 未结 5 2312
再見小時候
再見小時候 2021-02-19 21:29

i am new one so difficult to getting this error using resource module after calling service. can any one modify my mistake in code where i am getting wrong or just modified that

5条回答
  •  灰色年华
    2021-02-19 22:19

    From the documentation:

    Action isArray

    isArray – {boolean=} – If true then the returned object for this action is an array, see returns section.

    According to your code isArray = true. Set it to false and you can use an object instead of an array.

    app.factory('itemService', function ($resource) {
    return {
            getCategoryAndBrand   :  $resource("/user/categories_brands" ,{},{ TypeGetCategoryAndBrand:{method: 'get', isArray:true}})
        };
    });
    

    It's expecting you to pass in the parameters as an array not an object

    from your code

    $resource("/user/categories_brands" ,{},{ TypeGetCategoryAndBrand:{method: 'get', isArray:true}})

    If the documentation is to be believed than with the error your getting I'd try to pass this in the form of an array and not an object to see if you get the same response.

提交回复
热议问题