【问题标题】:AngularJS, AngularConfirm - Update Confirmation Dialog once function is completedAngularJS,AngularConfirm - 功能完成后更新确认对话框
【发布时间】:2017-12-19 16:54:33
【问题描述】:

我试图弄清楚如何在功能完成后更新以下 $ngConfirm 框。

点击提交后,出现如下(齿轮在旋转):

$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()。一旦该函数返回,我想将显示更新为以下内容(齿轮停止):

$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

【问题讨论】:

    标签: javascript jquery angularjs node.js


    【解决方案1】:

    有一个如何更改网站内容的示例。 https://craftpip.github.io/angular-confirm/#quickfeatures。在 Features 标题下,您可以单击标有“对话框”的按钮来查看示例。基本上,您需要将所有内容放在带有一些范围变量的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;
    });
    

    【讨论】:

    • 知道了。感谢您的帮助!
    • 欢迎您。感谢您向我介绍了一个新的、很酷的图书馆。我现在正在将 Angular Confirm 集成到我的项目中!
    猜你喜欢
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    相关资源
    最近更新 更多