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

前端 未结 5 2309
再見小時候
再見小時候 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:10

    Hope this answer is not too late.

    You should not fix this problem by putting a isArray:true statement to override "get" method's nature in your resource declaration.

    There are two ways to fix this problem.

    1.Use "query" method instead. It works like "get" method totally, but its isArray is set to true naturally.

    TypeGetCategoryAndBrand:{method: 'query'}
    

    2.On the server side, responding an object is a much easier and much smarter way. You can continue using "get" method on your client side and change your server side code from this:

    res.jsonp(articles);
    

    where articles is the result array, to this:

    res.jsonp(articles[0]);
    

提交回复
热议问题