AngularJS,AngularConfirm - 功能完成后更新确认对话框

时间:2017-07-14 14:31:53

标签: javascript jquery angularjs node.js

我试图弄清楚如何在函数完成后进行以下$ ngConfirm框更新。

点击提交后,出现以下内容(齿轮旋转):

enter image description here

$scope.inProgress = function(){
    $ngConfirm({
        theme: 'modern',
        icon: "fa fa-cog fa-spin fa-.5x fa-fw",
        title: 'File is downloading  Please wait.',
        content: "",
        buttons: {
        }
    });
};

显示此框后,将调用函数doSomething()。一旦该函数返回,我想将显示更新为以下(cog stops):

enter image description here

$scope.Complete = function(){
    $ngConfirm({
        theme: 'modern',
        icon: "fa fa-cog fa-.5x fa-fw",
        title: 'Spreadsheet Generated!',
        content: "File size is {$scope.fileSize}, Do you want to save it?",
        buttons: {
            'Yes, save my file': {
                downloadStuff();
                $ngConfirm('Spreadsheet saved to "Downloads" folder.');
            },
            'No, take me back': {
                action: function(){
                    $ngConfirm('Download has been cancelled.');
                }
            }
        }
    });
};

这就是我目前在控制器内的submit()函数中设置它的方式:

$scope.submit = function() {

    $scope.inProgress();

    $scope.doSomething();

    $scope.Complete();
};

使用上面的代码,我的应用程序显示了彼此分层的两个元素。我一直试图弄清楚如何在$ scope.doSomething()返回时使用$ scope.Complete()内部的详细信息进行$ scope.inProgress()更新。

有人可以就我需要做出哪些改变向我提出一些建议吗?我已经尝试在提交功能结束时修改$ scope.inProgress,但我总是显示一个新的确认框或者实际上没有改变某些内容。

我目前的想法是

$scope.ConfirmationControl = function() {
    $scope.inProgress(){
        storageService.doSomethingCool().then(
            $scope.inProgress() = //updated elements
        )
    }
} 

这有意义吗?我是关闭还是认为这完全错了?

提前感谢您的帮助! :)

Angular Confirm

1 个答案:

答案 0 :(得分:2)

有一个如何更改网站内容的示例。 https://craftpip.github.io/angular-confirm/#quickfeatures。在功能标题下,您可以单击标有“对话框”的按钮查看示例。基本上你需要在content:选项中放入一些范围变量。完成doSomething()后,设置$ scope变量(在这种情况下为$scope.somethingWasDone),并在对话框中设置ng-if。下面是一个未经测试的例子。

$scope.inProgress = function(){
    $scope.title = 'File is downloading. Please wait.';
    $ngConfirm({
        scope: $scope,
        icon: "fa fa-cog fa-spin fa-.5x fa-fw",
        content: '<h2>{{title}}</h2>' +
                 '<div ng-if="somethingWasDone">' +
                     '<div>File size is 250kb, do you want to save it?</div>' + 
                     '<button ng-click="downloadStuff()">Yes</button>' +
                     '<button ng-click="cancel()">No</button>' +
                 '</div>'
    });
};

// when your doSomething function is done
$scope.doSomething().then(function(result) {
    $scope.title = 'Spreadsheet Generated!';
    $scope.somethingWasDone = true;
});