[英]ui-bootstrap send click value to another controller
I have a main controller, and in it I call a modal. 我有一个主控制器,在其中我称为模态。 In this modal, I have a model called name and I would like to retrieve this field to store in my localStorage. 在这个模式中,我有一个名为name的模型,我想检索此字段以存储在我的localStorage中。 I searched on several sites but it did not work. 我在几个网站上搜索但是没有用。 My controller is this: 我的控制器是这样的:
app.controller('gameCtrl', ['$scope', '$uibModal', function($scope, $uibModal) {
$scope.openModal ()
$scope.congratulations = function() {
if ($scope.matchedCard.length == 2) {
alert('ACABOU')
clearInterval($scope.interval);
$scope.finalTime = $scope.timer.innerHTML;
$scope.player = [{
// Here i want save $scope._player (modal) in local storage
name: $scope._player = player;
moves: $scope.moves,
time: $scope.minute + " minutos " + $scope.second + " segundos"
}]
if (localStorage.getItem('players')) {
var totalPlayers = JSON.parse(localStorage.getItem('players'));
totalPlayers.push({
name: $scope.name,
moves: $scope.moves,
time: $scope.minute + " minutos " + $scope.second + " segundos"
})
localStorage.setItem('players', JSON.stringify(totalPlayers));
} else {
localStorage.setItem('players', JSON.stringify($scope.player));
}
var totalPlayers = JSON.parse(localStorage.getItem('players'));
};
}
$scope.openModal = function() {
$uibModal.open({
templateUrl: '../../../pages/component/modal.html',
controller: function($scope, $uibModalInstance) {
$scope.savePlayer = function(player) {
$scope._player = player;
$uibModalInstance.close();
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
}
}
})
};
I would like to send the input value, so I could retrieve it in the tro controller 我想发送输入值,所以我可以在tro控制器中检索它
With promise based modals such as $uibModal, send the data back as an argument to the .close
method: 使用基于promise的模态(如$ uibModal),将数据作为参数发送回.close
方法:
$scope.openModal = function() {
return $uibModal.open({
templateUrl: '../../../pages/component/modal.html',
controller: function($scope, $uibModalInstance) {
$scope.savePlayer = function(player) {
$scope._player = player;
̶$̶u̶i̶b̶M̶o̶d̶a̶l̶I̶n̶s̶t̶a̶n̶c̶e̶.̶c̶l̶o̶s̶e̶(̶)̶;̶
$uibModalInstance.close(player);
};
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
}
}
})
};
With $uibModal
, the promise is attached as the result
property of the instance object: 使用$uibModal
,promise将作为实例对象的result
属性附加:
var modalInstance = $scope.openModal();
modalInstance.result
.then(function (player) {
console.log("Modal closed with:", player);
}).catch(function (reason) {
console.log("Modal cancelled:", reason);
});
For more information, see 有关更多信息,请参阅
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.