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