resolve 在 angular ui 模型中不起作用

resolve doesnt work in angular ui modal

我正在尝试使用 angular bootstrap ui 显示一个模式,它解析控制器中的项目。问题是我无法在模态控制器中获得那些已解决的项目。

$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'
  });
}

模态控制器如下:

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');
}

}]);

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

history-controller.js:24 [Object]0: Objectlength: 1__proto__: Array[0]

showitems-modal-controller.js:8 Modal is initializing

showitems-modal-controller.js:9 undefined

所以我从这里了解到,调用了来自服务的成功回调,但它没有解析到模态控制器中,而是初始化了模态控制器。为什么会这样?

是不是因为我正在从成功回调中返回响应。如果是这样,我该怎么办?

你需要return resolve

中的承诺
resolve: {
  items: function(){
    var items = [];
    // missing "return"
    return   BillingService.getItemsInBill(bill).then(function(response){
      console.log(response);
      return response;
    });
  }
},