2015-01-02 36 views
-1

我有此代碼並且在socket.connect我希望能夠隱藏socket.disconnect中顯示的警報。

我在文檔中看到$ scope方法hideshowtoggle的引用,但是我怎麼能在這個例子中使用它們呢?

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

今天我覺得自己很蠢......

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(); 
});