繁体   English   中英

Angular-UI引导程序模式按钮将不执行功能

[英]Angular-ui bootstrap modal button will not execute function

我已经设置了模态

<script type="text/ng-template" id="myModalContent.html">
    <div class="modal-header">
        <h3 class="modal-title">Confirm</h3>
    </div>
    <div class="modal-body">
        <p>Are you sure you want to remove Two Factor Authentication from your profile?</p>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" ng-click="removeSetting()">Yes</button>
        <button class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
    </div>
</script>

按下“取消”按钮即可完成操作,只需关闭模式即可。 当用户点击“是”按钮时,我的问题就来了。 我的函数removeSetting()永远不会执行。

$scope.removeSetting = function() {
        TwoFactorAuthenticationService.removetAuthetication().then(function(data) {
            $scope.busy3=false;
            notifyService.alert("error", notifyService.getAlertText('2FactorRemovedToken'));
            $scope.busy=true;
            $timeout(function() {
                $scope.templateUrl = 'twofactorsetup/step1.html';
            }, 3000);
        }, function() {
            notifyService.alert("error", notifyService.getAlertText('2FactorRemoveTokenFailed'));
        });
    };

那就是应该被调用和执行的功能。 我想念什么?

将这样的代码放入模式初始化中

$modal.open({
    templateUrl: 'myModalContent.html',
    scope: $scope,
    controller: function($scope, $modalInstance) {
        $scope.removeSetting = function() {
            //place your code here or call function from parent scope
            $scope.$parent.removeSetting();
            $modalInstance.dismiss('cancel');
        };
    }
});

如果不使用父范围,则不需要范围参数。

或者,您可以从模板这样的父作用域使用调用函数(通过使用$ parent.removeSetting()调用)

<script type="text/ng-template" id="myModalContent.html">
    <div class="modal-header">
        <h3 class="modal-title">Confirm</h3>
    </div>
    <div class="modal-body">
        <p>Are you sure you want to remove Two Factor Authentication from your profile?</p>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" ng-click="$parent.removeSetting()">Yes</button>
        <button class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
    </div>
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM