2017-07-07 57 views
3

我在我的角度应用中使用了Sweet-alert如何关闭ajax请求完成时的甜蜜提醒

function GetDataFromServer(url) { 
     SweetAlert.swal(
    { 
     title: "", 
     text: "Please wait.", 
     imageUrl: "../../app/app-img/loading_spinner.gif", 
     showConfirmButton: false 
    }); 
     return $http.get(url) 
     .then(success) 
     .catch(exception); 
     function success(response) { 
      //SweetAlert.swal(
      // { 
      //  title: "", 
      //  text: "data loaded", 
      // }); 
      return response.data; 
     } 
     function exception(ex) { 
      return (ex); 
     } 

    } 

询价#1(我这个职位的主要目标)

What I am looking for is when the ajax request completes i.e., controls enters in the then(), Sweet alert should automatically hide.

询价#2 还同时请求处理,我不希望有关闭弹出按钮(OK按钮)在甜蜜的警报。

enter image description here 根据文档,showConfirmButton: false应该隐藏它,但它不是。

任何帮助/建议高度赞赏。
谢谢。

+0

等一下,你在问什么,看起来你在问这里两个不同的东西。你想隐藏'ok'按钮吗?还是想要以弹出的方式关闭? – Relic

+0

@Relic,是的,你是对的我更新了帖子 –

+0

我编辑了我的答案,请参阅完整的成功! – Relic

回答

4

为了在弹出完成时自动隐藏弹出窗口,您应该将初始弹出窗口设置为一个变量,以便稍后访问它。也许:

function GetDataFromServer(url) { 
    SweetAlert.swal({ 
     title: "", 
     text: "Please wait.", 
     imageUrl: "../../app/app-img/loading_spinner.gif", 
     showConfirmButton: false 
    }); 
    return $http.get(url) 
    .then(success) 
    .catch(exception); 
    function success(response) { 
     swal.close() 
     return response.data; 
    } 
    function exception(ex) { 
     return (ex); 
    } 

} 

这是正确的:https://t4t5.github.io/sweetalert/在靠近底部的方法部分。

由于您没有具体的'方式'您想要隐藏确定按钮,您只是在寻找建议,您可以随时使用一个小CSS来定位它,并给它设置ol display: none;设置。

+0

你的帖子不清楚,你可以请添加适当的片段? –

+0

我会更新,但这是正确的JS – Relic

+0

'TypeError:SweetAlert.close不是一个函数' –

1

可以在上下部分使用过甜的对象close方法请参见文档

https://t4t5.github.io/sweetalert/

swal.close(); - >以编程方式关闭当前打开的SweetAlert。

self.showProgress = function(message) { 
    swal({ title: message }); 
    swal.showLoading(); 
}; 

self.hideProgress = function() { 
    swal.close(); 
};