ngDialog确认多次点击

时间:2016-11-30 12:04:20

标签: angularjs ng-dialog

通过ngDialog弹出窗口我将数据收集到$ scope数组。如果用户多次单击确认按钮,则会多次添加数据。我已经通过$ scope变量尝试了ngDisable来禁用按钮,但遗憾的是ngDialog弹出窗口在确认功能完成之前没有获取范围更改。 https://jsfiddle.net/lasith011/11cdp05c/

var myApp = angular.module('myApp',['ngDialog']);

myApp.controller('MyCtrl', function ($scope, ngDialog) {
        $scope.names = [];
    $scope.openDialog = function(){
        ngDialog.open({
        scope: $scope,
        template: 'templateForm',
        closeByDocument: false,
        controller: 'PopUpController'
      });
    }
});
myApp.controller('PopUpController', function($scope, ngDialog, $timeout){
    $scope.cancel = function(){
    ngDialog.close();
  };
  $scope.submit = function(){
    $scope.disable = true;
    //Some calculation
    $timeout(function(){
        $scope.names.push($scope.varName);
      ngDialog.close();
    }, 1000);   
    $scope.disable = false;
  };
});

1 个答案:

答案 0 :(得分:0)

为什么要用1000毫秒添加$ timeout?删除它应该没问题。

myApp.controller('PopUpController', function($scope, ngDialog){
    $scope.cancel = function(){
        $scope.closeThisDialog();
    };
    $scope.submit = function(){
        $scope.disable = true;
        //Some calculation
        $scope.names.push($scope.varName);
        $scope.closeThisDialog('cancel');
        $scope.disable = false;
    };
});

https://jsfiddle.net/ramseyfeng/3spbjpt8/