javascript - Angularjs 无法解析返回的 promise

标签 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) 

请问可能是什么问题,我已经尝试了所有我能做的事情

最佳答案

在你的工厂试试这个:

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

在你的 Controller 中:

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

关于javascript - Angularjs 无法解析返回的 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22793875/

相关文章:

javascript - 如何在单个网页中拥有多个 Angular 应用程序?

javascript - 访问所选 Kendo TreeView 节点的子节点

javascript - 我的 javascript 函数在页面刷新时不会触发

javascript - 如何在 Angular Protractor 中使用类单击日历图标

javascript - AngularJS帮助: Connecting a Search Input into an REST Interface

angularjs - 我需要什么用于Web服务器开发的NodeJS工具(框架,IDE等)?为什么?

javascript - Kendo UI Sticky/Fixed/Floated Header 扰乱了整体结构

javascript - 当变量发生变化时更新服务中的变量

javascript - 带逗号分隔符的 ng-repeat 输入

angularjs - 在 AngularJS 的服务中存储常量?