【发布时间】:2016-01-18 01:48:35
【问题描述】:
我正在尝试使用 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 模态正在初始化
showitems-modal-controller.js:9 未定义
所以我从这里了解到的是调用了服务的成功回调,但它没有解析到模态控制器中,而是初始化了模态控制器。为什么会这样?
是不是因为我从成功回调中返回响应。如果是这样,我该怎么办?
【问题讨论】:
标签: javascript angularjs twitter-bootstrap angular-ui-bootstrap bootstrap-modal