【问题标题】:AngularJS ngResource not workingAngularJS ngResource 不工作
【发布时间】:2014-07-16 19:15:01
【问题描述】:

我有以下问题: 我正在使用 ui-router 在页面上显示 ng-grid。但是 $resource 在发送到服务器时不会更改 url 中的参数(例如http://bcunix.test:8080/MYAPP/eq/:Id)。 :Id 没有改变,我收到了来自服务器的错误请求,因为我正在发送 :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"
            }
        });
    }]);

})();

结果: GET http://bcunix.test:8080/MYAPP/eq/:Id400(错误请求)

任何帮助/提示将不胜感激。

谢谢, 阿迪普

【问题讨论】:

  • 你确定这应该被忽略吗?你不需要制作 2 个模板 URL 吗?

标签: angularjs rest ngresource


【解决方案1】:

哈哈,

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

更新到最新版本,现在可以正常使用了。

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

最好的问候, 阿迪普

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2016-03-17
    相关资源
    最近更新 更多