Javascript 解析在angular ui模式下不起作用
我试图显示一个模式使用角度引导用户界面解析控制器中的项目。问题是我无法在模态控制器中获得已解决的项Javascript 解析在angular ui模式下不起作用,javascript,angularjs,twitter-bootstrap,angular-ui-bootstrap,bootstrap-modal,Javascript,Angularjs,Twitter Bootstrap,Angular Ui Bootstrap,Bootstrap Modal,我试图显示一个模式使用角度引导用户界面解析控制器中的项目。问题是我无法在模态控制器中获得已解决的项 $scope.showItemsInBill = function(bill){ var modalInstance = $uibModal.open({ animation: $scope.anismationsEnabled, resolve: { items: function(){ var items = []; Billin
$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__;u:Array[0]
showitems模态控制器.js:8模态正在初始化
showitems modal controller.js:9未定义
因此,我从这里了解到,调用了来自服务的成功回调,但没有解析为模态控制器,而是初始化了模态控制器。为什么会这样
是因为我从成功回调返回响应。如果是,在这种情况下我能做什么?您需要在解决方案中返回承诺
resolve: {
items: function(){
var items = [];
// missing "return"
return BillingService.getItemsInBill(bill).then(function(response){
console.log(response);
return response;
});
}
},
你需要在决议中回报承诺
resolve: {
items: function(){
var items = [];
// missing "return"
return BillingService.getItemsInBill(bill).then(function(response){
console.log(response);
return response;
});
}
},
我的成功回调中的返回是什么?它的作用是什么?返回值以便下一个
可以访问它。您看不到nextthen
,但它在内部用于在controller中创建注入参数,在我的成功回调中返回什么?它的作用是什么?返回值以便下一个可以访问它。您看不到nextthen
,但它在内部用于在控制器中创建注入参数