AngularJS 引导模态结果而不关闭

AngularJS Bootstrap Modal result without closing

本文关键字:结果 模态 AngularJS      更新时间:2023-09-26

我正在尝试将m-e-controy Angular-Dialog-Service实现到我的AngularJS应用程序中。我想制作一个"编辑"对话框来更改对象的值。该应用程序由 FactorController 控制, 打开一个对话框,传递要编辑的因子并将FactorDialogController绑定到它。

这工作正常。我知道我可以通过拍摄$modalInstance.close(data)将数据返回给FactorController.但这会关闭对话框。我如何只返回数据,保留对话框,在FactorController中做一些验证工作,当一切正常时,然后关闭对话框?请参阅评论。

module.controller('FactorController', ['FactorREST', '$scope', 'dialogs', function($FactorREST, $scope, dialogs) {
    ...
    this.editFactor = function(factor) {
        var dlg = dialogs.create('/js/angularjs/template/custom/factor.html','FactorDialogController',factor, {size: 'md', copy:true});
        dlg.result.then(function(data){
            _this.connectionStatus = _this.STATUS_LOADING;
            $FactorREST.put({id: factor.id}, data).$promise.then(function(response) {
                _this.connectionStatus = _this.STATUS_DONE;
            }).catch(function() {
                _this.connectionStatus = _this.STATUS_DONE;
                connectionErrorDialog();
            });
        });
    };
)
.controller('FactorDialogController',function($scope,$modalInstance,data){
    $scope.tmpFactor = data;
    /* Callbacks**************************************************
    *************************************************************/
    $scope.save = function() {
        $modalInstance.close($scope.tmpFactor);
        // don't close, but something linke $modalInstance.return($scope.tmpFactor)
    };
    $scope.abort = function() {
        $modalInstance.dismiss('Abgebrochen');
    };
});

最好的方法是使用服务。无论如何,您应该将逻辑而不是控制器放在服务中。

一般来说,控制器是你用范围连接事物的地方。

除此之外,应该去工厂/服务。