我正在嘗試使用Angular-Strap和$alert
服務在我的AngularJS應用程序中實現自動警報。然而,迄今爲止這麼好,我留下了一個我似乎無法解決的問題。Angular-Strap Alerts:在alert.hide()觸發時無法捕獲
當我使用duration
屬性或alert.hide()
命令隱藏$alert
時,我可以設置一個回調來捕獲回調嗎?我想在警報進入隱藏狀態時運行一個函數。
我的代碼片段看起來是這樣的:
var alertContent = '';
// Define the critical alert
var criticalAlert = $alert({
templateUrl: 'templates/critical.alert.tpl.html',
title: ' Critical Alert Detected!',
content: alertContent,
container: 'body',
type: 'danger',
dismissable: false,
duration: '20',
show: false
});
...
alertContent = 'Foo Bar!';
...
criticalAlert.$promise.then(criticalAlert.hide);
...
$scope.$on('alert.hide', function() {
console.log('Alert Hidden');
});
我已經找到了合適的解決方案,您的問題? –