【问题标题】:AngularJS - Error: value.push is not a functionAngularJS - 错误:value.push 不是函数
【发布时间】:2014-03-22 04:31:50
【问题描述】:

我有这样定义的服务 ->

storegrServices.factory('productList', ['$resource', function($resource) {
    return $resource('', {},{
        query: {url:'/apis/productshome.php', method:'GET', isArray:false},
        getProductDetail: {url:'/apis/getproductdetail.php', method:'POST', isArray:true}
    });
}]);

在控制器中,这就是我调用 POST 的方式 ->

storegrControllers.controller('productPageCtrl', ['$scope','productList','$routeParams', function($scope, productList, $routeParams) {
    $scope.postVariable = new productList();
    $scope.postVariable.productcode =  $routeParams.code;
    $scope.postVariable.$getProductDetail();
}]);

这会将产品代码发送到服务器,服务器会在响应中返回一个数组。我使用过 isArray: true,但它仍然给我一个错误。我的代码中没有“值”变量/对象。

请建议我该如何解决这个问题。

这是我得到的完整错误 ->

Error: value.push is not a function
resourceFactory/</Resource[name]/promise</<@http://storegr.com/js-lib/angular-resource.js:530
q@http://storegr.com/js-lib/angular.min.js:7
resourceFactory/</Resource[name]/promise<@http://storegr.com/js-lib/angular-resource.js:529
yd/e/k.promise.then/w@http://storegr.com/js-lib/angular.min.js:92
yd/e/k.promise.then/w@http://storegr.com/js-lib/angular.min.js:92
yd/g/<.then/<@http://storegr.com/js-lib/angular.min.js:93
zd/this.$get</h.prototype.$eval@http://storegr.com/js-lib/angular.min.js:101
zd/this.$get</h.prototype.$digest@http://storegr.com/js-lib/angular.min.js:98
zd/this.$get</h.prototype.$apply@http://storegr.com/js-lib/angular.min.js:101
f@http://storegr.com/js-lib/angular.min.js:66
F@http://storegr.com/js-lib/angular.min.js:70
md/</B.onreadystatechange@http://storegr.com/js-lib/angular.min.js:71
http://storegr.com/js-lib/angular.min.js
Line 84

这是来自服务器的响应 ->

[{"sno":21,"cat1":"Beverages","cat1code":"B","cat2":"Carbonated Drinks&Fruit Drinks","cat2code":"CDD","cat3":"Fruit Juices","cat3code":"FJ","cumulative":20,"brand":"Real Juice","product":"Apple","productcode":"B-CDD-FJ-1","imagename":"B-CDD-FJ-1","weight":200,"unit":0,"mrp":20,"margin":0,"wsp":0,"vat":0,"hbprice":0,"discount":0,"availableqty":0,"availableprice":0,"existingqty":0,"existingprice":0,"addedqty":0,"addedprice":0,"soldqty":0,"soldprice":0,"tags":"home"}]

【问题讨论】:

    标签: angularjs post angularjs-resource


    【解决方案1】:

    我能够解决这个问题,在这里回答它,这样它也可以使其他人受益。

    我将我的数组响应修改为这样的 json 对象并且它起作用了。

    { "product":
    [{"sno":21,"cat1":"Beverages","cat1code":"B","cat2":"Carbonated Drinks&Fruit Drinks","cat2code":"CDD","cat3":"Fruit Juices","cat3code":"FJ","cumulative":20,"brand":"Real Juice","product":"Apple","productcode":"B-CDD-FJ-1","imagename":"B-CDD-FJ-1","weight":200,"unit":0,"mrp":20,"margin":0,"wsp":0,"vat":0,"hbprice":0,"discount":0,"availableqty":0,"availableprice":0,"existingqty":0,"existingprice":0,"addedqty":0,"addedprice":0,"soldqty":0,"soldprice":0,"tags":"home"}]
    }
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 2013-10-13
      • 2015-08-07
      • 1970-01-01
      • 2016-04-18
      • 2015-11-07
      • 1970-01-01
      • 2019-12-27
      • 2016-02-05
      • 2017-12-03
      相关资源
      最近更新 更多