简体   繁体   English

ui-bootstrap将点击值发送给另一个控制器

[英]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.

相关问题 如何在我的控制器中访问AngularJS ui-bootstrap datepicker值 - How to access the AngularJS ui-bootstrap datepicker value in my controller Ui-Bootstrap文档单击“手风琴”折叠 - Ui-Bootstrap document click Accordion collapse angularjs-从另一个控制器访问ui-bootstrap模式关闭和关闭功能 - angularjs - Accessing ui-bootstrap modal dismiss and close function from another controller 为什么不从ui-bootstrap模态控制器绑定到$ scope字符串值? - Why won't binding to a $scope string value from a ui-bootstrap modal controller work? ui-bootstrap:从指令控制器内访问模式实例 - ui-bootstrap: accessing modal instance from within directive controller 从控制器动态加载Angular UI-Bootstrap手风琴 - Dynamically load Angular UI-Bootstrap accordian from controller UI-Bootstrap日期选择器不会在嵌入式控制器范围内调用函数 - UI-Bootstrap datepicker does not call function on inline controller scope 如何在控制器中设置分页最后一页ui-bootstrap? - how to set pagination last-page ui-bootstrap in the controller? 更改角度ui-bootstrap模式控制器中的$ rootScope - changing $rootScope inside angular ui-bootstrap modal controller 单击链接ui-bootstrap响应时,导航栏未关闭 - navbar didnt close when click link ui-bootstrap responsive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM