简体   繁体   English

角度资源-$ resource:badcfg

[英]angular resource - $resource:badcfg

My angular throws me 我的角度使我投掷

Error: [$resource:badcfg] Error in resource configuration for action query . 错误:[$ resource:badcfg]操作query资源配置错误。 Expected response to contain an array but got an object 预期响应包含一个数组但有一个对象

I have no idea why this happens. 我不知道为什么会这样。 I have a db with schools, and each schools has a city property. 我有一个与学校的数据库,每个学校都有一个城市财产。 i'm trying to get all the schools in a given city. 我正在尝试让一个城市的所有学校。 On the server, my controller has a function which is supposed to do exactly that: 在服务器上,我的控制器有一个功能应该可以做到这一点:

getSchoolByData: function(req, res, next) {
    School.find({city: req.params.reqCity}).exec(function (err, collection) {
        if (err) {
            console.log("Could not load desired school: " + err);
        }
        res.send(collection);

    });
}

On my client side I have a resource and another controller: resource: 在客户端,我有一个资源和另一个控制器:资源:

app.factory('SearchSchoolResource', function($resource) {
    var SearchSchoolResource = $resource('/schoolSearchResult/:reqCity', {city: 'reqCity'}, { update: {method: 'PUT', isArray: false}});
    return SearchSchoolResource;
}); 

controller: 控制器:

app.controller('SearchSchoolCtrl', function($scope, $routeParams, SearchSchoolResource) {
    $scope.schools = SearchSchoolResource.query({city: $routeParams.reqCity});
});

I have no idea which one of these fails to work properly and I have no idea how to check. 我不知道其中哪一个不能正常工作,也不知道如何检查。 I'm new to angular and node, and I spent over 72 hours on this, so if someone can tell me how to fix this, it will be amazing! 我是angular和node的新手,我花了72个小时以上,所以如果有人可以告诉我如何解决这个问题,那就太好了! Other than that I managed to return all the schools, and a single school based on given id just fine, but returning schools based on city fails. 除此之外,我设法退回了所有学校,并且基于给定id的一所学校还可以,但是基于城市的退回学校却失败了。

EDIT: 编辑:

If I just put the name of the city in the find function like 如果我只是将城市名称放在诸如

... find({city: 'name'}) ...

It works, but if I use req.params.reqCity it doesn't. 它可以工作,但是如果我使用req.params.reqCity则不能。 I can't figure out why it doesn't work, it seems like req.params.reqCity is returning something different and not the given city name. 我不知道为什么它不起作用,好像req.params.reqCity返回的是不同的东西,而不是给定的城市名称。 Tried just using .ToArray instead of .exec and it doesn't work again. 尝试仅使用.ToArray而不是.exec,它不再起作用。 Can't figure out what the req.params.reqCity returns and still can't figure out how to fix this. 无法找出req.params.reqCity返回什么,仍无法找出如何解决此问题。

Try this way, it should work. 尝试这种方式,它应该可以工作。 In addition to get i am also adding other operation's syntax. 除了得到我还添加其他操作的语法。

Service: 服务:

 app.factory('SchoolService',function($resource){
            return $resource('/schoolSearchResult/:reqCity', 
            {
                reqCity: '@reqCity'
            },
            {
                'update': { method:'PUT' }
            },
            {
                'get': { method: 'GET', isArray: false }
            },
            {
                'delete': { method: 'DELETE'}
            }
        );
        });

controller: 控制器:

app.controller('SearchSchoolCtrl', function($scope, $routeParams, SchoolService) {
        var schoolService = new SchoolService();
        schoolService.$get({reqCity : $routeParams.reqCity},function(result){
                    $scope.schools = result;
                });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度资源:错误:$ resource:badcfg - Angular Resource: Error: $resource:badcfg 另一个错误:Angular webapp中的[$ resource:badcfg] - Another Error: [$resource:badcfg] in Angular webapp 角度错误的配置错误:[$ resource:badcfg]查询 - Angular bad config Error: [$resource:badcfg] query 使用angular调用sharepoint rest服务时的$ resource:badcfg - $resource:badcfg when calling sharepoint rest service using angular 保存后出现$ resource:badcfg错误 - $resource:badcfg error following save Angular JS-单元测试$ resource.get时出现[$ resource:badcfg]错误,但在控制器上很好 - Angular JS - Getting [$resource:badcfg] error when unit testing $resource.get but is fine on controller 有没有办法在控制台中修复资源badcfg get错误 - Is there a way to fix resource badcfg get error in console 角度Js。 如何修复错误:$ resource:badcfg响应与配置的参数不匹配 - Angular Js. How fix Error: $resource:badcfg Response does not match configured parameter angular.js 1.4.8错误:$ resource:badcfg。 普通浏览器中存在错误,但隐身模式不存在 - angular.js 1.4.8 Error: $resource:badcfg. Error present in normal browser but not Incognito 错误:使用Jasmine测试资源服务时,[$ resource:badcfg]查询 - ERR: [$resource:badcfg] query when testing a resource service with Jasmine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM