AngularJS Bootstrap 没有关闭的模态结果

AngularJS Bootstrap Modal result without closing

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

这很好用。我知道我可以通过拍摄 $modalInstance.close(data) 来 return 数据到 FactorController。但这会关闭对话框。我如何只 return 数据,保留对话框,在 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');
    };
});

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

一般来说,controller 是你连接 scope 的地方。

除此之外应该转到 factory/service。