2

我正在使用引導警報來顯示應用程序消息。我使用$超時功能自動關閉警報。自動關閉後未顯示自舉警報對話框

$scope.alerts.push({header: header, msg: message, type: type}); 
      $timeout(function() { 
       $scope.alerts.splice(0, 1); 
      }, 3000); 

第一次顯示引導警報,它在3秒內自動閉鎖。之後,它不會顯示應用程序中執行的任何操作的錯誤/信息消息。有什麼我需要補充。?我是角js新手。請幫忙。

回答

2

我認爲你在輪詢$timeout。希望這將幫助你

在HTML

<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</alert> 
    <button class='btn btn-default' ng-click="addAlert()">Add Alert</button> 

在控制器

$scope.alerts = []; 

    $scope.addAlert = function() { 
    $scope.alerts.push({msg: 'Another alert!'}); 
    $scope.autoHide(); 
    }; 
    $scope.autoHide =function(){ 
        $timeout(function() { 
         $scope.alerts.splice(0, 1); 
        }, 3000); 
    } 

    $scope.closeAlert = function(index) { 
    $scope.alerts.splice(index, 1); 
    }; 
+0

<警報納克重複= 「警報中的警報」 \t \t \t類型= 「alert.type」 靠近= 「closeAlert($指數)」> \t \t {{alert.header}} \t \t
\t \t {{alert.msg}} \t \t 這是圖。我試圖在控制器中添加autohide()。仍然問題仍然存在 – Poppy

+0

你能夠提供一個小提琴或你的代碼的笨拙。 – Shivaraj

+0

否則請嘗試http://mgcrea.github.io/angular-strap/##alerts – Shivaraj

3

引導警報從DOM當你點擊關閉刪除,你需要的,如果你使用close.bs.alert事件希望警報留在DOM中並被重用。

<div class="alert alert-warning collapse" id="my-alert"> 
     <a href="#" data-dismiss="alert" class="close">&times;</a> 
     <p>My alert.</p> 
</div> 

var alert = $("#my-alert");  
alert.on("close.bs.alert", function() { 
    alert.hide(); //hide the alert 
    return false; //don't remove it from DOM 
}); 

#alerts-usage瞭解更多。