Angularjs无法解决返回的承诺

时间:2014-04-01 18:24:13

标签: javascript angularjs

我有两个下拉列表与下面的代码级联,但是没有呈现返回到第二个下拉列表的JSON,因为返回的promise未正确解析

 <div class="row" style="padding-bottom:50px;width:85%;">
    <select data-ng-model="search.astate"  data-ng-options="s.StateID as s.StateName for s in astates" ng-change="agetLGA()">
          <option value="">Filter by state</option>
       </select>
   </div>
    <div class="row" style="width:85%;">
    <select data-ng-model="search.algovt"  data-ng-options="c.StateLGId as c.LGName for c in algovts" data-ng-disabled="!lgovts">
          <option value="">Filter by local govt</option>
       </select>
   </div>

这是在更改第一个下拉列表时调用的代码

$scope.agetLGA = function () {
        var stateId = $scope.search.astate;
        $scope.algovts = artFact.getLGA().save({stateId:stateId}, function (response){
            $scope.algovts = response.data;
        });

这是getLGA工厂定义

 getLGA: function (stateId) {
            return $resource('/Home/GetLGA/', { stateId: '@stateId' }, { update: { method: 'POST' } });

    }

给出的错误就是这个

Error: [$resource:badcfg] object
http://errors.angularjs.org/1.2.13/$resource/badcfg?p0=array
    at http://localhost:53536/Scripts/angular.js:78:12
    at a.module.factory.f.(anonymous function).p.then.m.$resolved (http://localhost:53536/Scripts/angular-resource.min.js:8:517)
    at deferred.promise.then.wrappedCallback (http://localhost:53536/Scripts/angular.js:11033:81)
    at deferred.promise.then.wrappedCallback (http://localhost:53536/Scripts/angular.js:11033:81)
    at http://localhost:53536/Scripts/angular.js:11119:26
    at Scope.$get.Scope.$eval (http://localhost:53536/Scripts/angular.js:12045:28)
    at Scope.$get.Scope.$digest (http://localhost:53536/Scripts/angular.js:11871:31)
    at Scope.ng.config.$provide.decorator.$delegate.__proto__.$digest (<anonymous>:844:31)
    at Scope.$get.Scope.$apply (http://localhost:53536/Scripts/angular.js:12151:24)
    at Scope.ng.config.$provide.decorator.$delegate.__proto__.$apply (<anonymous>:855:30) 

请问有什么问题,我已尽力了

1 个答案:

答案 0 :(得分:0)

在你的工厂试试这个:

return {
    getLGA: $resource('/Home/GetLGA/', {}, { update: { method: 'POST' } });
}

在你的控制器中:

$scope.agetLGA = function () {
    var stateId = $scope.search.astate;
    $scope.algovts = artFact.getLGA.update({stateId:stateId}, function (response){
        $scope.algovts = response.data;
    }));
};