我有一个主控制器,在其中我称之为模态。在这个模式中,我有一个名为 name 的模型,我想检索这个字段以存储在我的 localStorage 中。我在几个网站上搜索,但没有奏效。我的控制器是这样的:
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');
}
}
})
};
我想发送输入值,所以我可以在 tro 控制器中检索它