How to hide angular-strap $alert

你说的曾经没有我的故事 提交于 2019-12-16 18:02:26

问题


I have this code and on socket.connect I want to be able to hide the alert that was shown in socket.disconnect.

I see there is a reference in the docs to $scope methods hide, show, and toggle but how can I use them in this example?

socket.on('disconnect', function () {

  // Show login error message
  $alert({
    title: 'Connection lost.',
    content: 'Please reload the page.',
    placement: 'top-right',
    type: 'danger',
    show: true
  });
});

socket.on('connect', function () {
  // TODO: Check if connection alert is showing and if it is, hide it
});

回答1:


I feel stupid today...

var alert = $alert({
    title: 'Connection lost.',
    content: 'Please reload the page.',
    placement: 'top-right',
    type: 'danger',
    show: false
});

socket.on('disconnect', function () {
    alert.show();
});

socket.on('connect', function () {
    alert.hide();
});


来源:https://stackoverflow.com/questions/27746193/how-to-hide-angular-strap-alert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!