首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析在角度ui模型中不起作用

解析在角度ui模型中不起作用
EN

Stack Overflow用户
提问于 2016-01-18 01:48:35
回答 1查看 1.6K关注 0票数 0

我试图显示一个使用角度引导ui的模式,它解析控制器中的项。问题是我无法在模态控制器中得到那些已解决的项目。

代码语言:javascript
复制
$scope.showItemsInBill = function(bill){
  var modalInstance = $uibModal.open({
    animation: $scope.anismationsEnabled,
    resolve: {
      items: function(){
        var items = [];
        BillingService.getItemsInBill(bill).then(function(response){
          console.log(response);
          return response;
        });
      }
    },
    templateUrl: 'templates/showitems-modal.html',
    controller: 'ShowItemsModalCtrl',
    backdrop: 'static'
  });
}

该模态控制器如下:

代码语言:javascript
复制
angular.controller('ShowItemsModalCtrl', ['$scope', '$uibModalInstance', 'BillingService', 'items', function ($scope, $uibModalInstance, BillingService, items) {

init();

function init(){
  console.log('Modal is initializing');
  console.log(items);
  $scope.items = items;
}

$scope.cancel = function () {
  $uibModalInstance.dismiss('cancel');
};

$scope.printBill = function(){
  console.log('printing bill');
}

]);

我在控制台中得到的响应是:

24:24 Object0:对象长度: 1__proto__:数组 is :8 Modal正在初始化 模型.控制器.:9未定义

因此,我从这里了解到,服务的成功回调是被调用的,但是它没有被解析为模态控制器,而是初始化了模态控制器。为什么会发生这种情况?

是因为我正在返回成功回调的响应。如果是这样的话,我能在这种情况下做些什么呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-18 03:08:25

你需要在决心中兑现诺言

代码语言:javascript
复制
resolve: {
  items: function(){
    var items = [];
    // missing "return"
    return   BillingService.getItemsInBill(bill).then(function(response){
      console.log(response);
      return response;
    });
  }
},
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34846087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档