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

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

    You are getting an object that contain two arrays.

    My guess is that in your code before you started with the console.log outputs, you were setting categories = response;.

    You need to set it to: categories = response.categories;

    Here:

    app.controller('itemsFormController', function ($rootScope, $scope, itemService, $location, $cookies, $routeParams) {
            itemService.getCategoryAndBrand.TypeGetCategoryAndBrand({}, function(response){
    
                    categories = response.categories;
                    console.log(response);
    
                },function(errorResponse){
                    console.log(errorResponse);
                }
            );  
    });
    

    This might help to understand the problem, also:

    AngularJS $resource query returns array with a function in it, which is not does not fit well when iterating through data

提交回复
热议问题