문제

Here is my js code

var MYModule = angular.module('myApp', ['ngRoute', 'myAppServices'])
    .directive('loading',   ['$http', loadingDirective])
    .config(myRouter);

angular.module('myAppServices', ['ngResource'])
    .factory('Users', function($resource) {
        return $resource('/MY/system/users');
    });

function UsersCtrl($scope, Users) {
    $scope.users = Users.query();
}

in my html code just using this

<div ng-repeat="item in users">Hello</div>

Although I am getting request in my server code at /MY/system/users but the browser is throwing error

Error: [$resource:badcfg] http://errors.angularjs.org/1.2.16/$resource/badcfg?p0=array&p1=object
    at Error (native)
도움이 되었습니까?

해결책

See this error documentation: https://docs.angularjs.org/error/$resource/badcfg

This occurs when angular is expecting an array or an object, and receiving the opposite. query() expects an array to be returned from your endpoint, while get() expects an object.

Also, you should change your query() syntax above to:

Users.query().then(function(result){
    $scope.users = result;
});

This is because angular is phasing out the automatic handling of promises returned via $http.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top