gpt4 book ai didi

angularjs - 关闭 modalInstance 时发送多个参数

转载 作者:行者123 更新时间:2023-12-03 07:06:08 27 4
gpt4 key购买 nike

我有一个带有模态的 Angular 项目,我想在关闭时发送多个(两个)参数,问题是它给出的第二个参数未定义,我的代码如下

/*Modal controller*/
angular.module('assetModule')
.controller('assetModalLocationCtrl', ['locationRESTService','$modalInstance','$scope', '$q', assetModalLocationCtrl]);

function assetModalLocationCtrl (locationRESTService, $modalInstance, $scope, $q) {

this.ok = function () {
$scope.info.selected = selected ($scope.data.locations)
$modalInstance.close($scope.data.locations, $scope.info.selected);
};
}

/*Controller that invoke the modal*/
this.modalLocation = function modalLocation (size){
var modalInstance = $modal.open({
animation: this.animationsEnabled,
templateUrl: 'views/asset/assetLocationModal.html',
controller: 'assetModalLocationCtrl',
controllerAs: 'modalLocation',
size: size,

});

modalInstance.result.then(function (selectedItem, locationList) {
console.log(selectedItem);
console.log(locationList);
}, function () {
console.log('Modal dismissed at: ' + new Date());
});
}

最佳答案

你不能这样做,因为 promise 只能解析为一个值,你可以将它们组合成一个对象。

 $modalInstance.close({locations: $scope.data.locations, selected: $scope.info.selected});  

并在 promise 得到解决时相应地阅读它们。

modalInstance.result.then(function (transferData) {
console.log(transferData.selected);
console.log(transferData.locations);
}, function () {
console.log('Modal dismissed at: ' + new Date());
});

旁注:

使用 Typescript 或 Babel 或任何其他 ES6 polyfill,您可以使用对象解构语法并编写如下:

modalInstance.result.then({locations, selected}) => {
console.log(locations);
console.log(selected);
}

关于angularjs - 关闭 modalInstance 时发送多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33268172/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com