0

I have the following problem: I am using ui-router to display a ng-grid on a page. But the $resource is not changing the parameter from the url when sending to server (e.g. http://bcunix.test:8080/MYAPP/eq/:Id). The :Id is not changed, and I get Bad request from the server because I am sending :Id.

index.js

(function() {
'use strict';
var brgEquipments = angular.module('brg.equipments',
        [
            'ui.router',
            'brg.equipments.controllers'
        ]);
brgEquipments.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/equipments/list');

    $stateProvider.state('list', {
        url: '/equipments/list',
        templateUrl: '/scripts/modules/equipments/views/grid_list.html',
        controller: 'equipmentsListCtrl',
        resolve: {
            // A string value resolves to a service
            eqService: 'eqService',
            // A function value resolves to the return
            // value of the function
            equipments: function(eqService) {
                return eqService.query().$promise;
            }
        }
    });

});

})();

service.js

(function() {
'use strict';
var eqCtrls = angular.module('brg.equipments.controllers');

eqCtrls.factory('eqService', ['$resource', function($resource) {
        return $resource("http://bcunix.test:8080/MYAPP/eq/:Id",
                { Id: "@Id"},
        {
            update: {
                method: "PUT"
            },
            remove: {
                method: "DELETE"
            }
        });
    }]);

})();

Result: GET http://bcunix.test:8080/MYAPP/eq/:Id 400 (Bad Request)

Any help / hints would be appreciated.

Thanks, AdiP

4

1 回答 1

0

哈哈,

所以最后我想通了。看起来 bower install ngResource 不等于 bower install angular-resource。我使用了错误版本的 ngResource。

更新到最新版本,现在它正在工作。

感谢 ThomasP1988 有兴趣解决我的问题。

最好的问候, AdiP

于 2014-07-16T11:15:01.423 回答