我已经更新了 @daydreamer 创建的 plunker 以显示多个警报并自动隐藏。如果有人想自定义多个警报,请查看此Plunker Link
与@DerekR 相同的一半代码,我只是对其进行了自定义
var app = angular.module('myApp', ['$strap.directives']);
app.directive('notification', function($timeout){
return {
restrict: 'E',
replace: true,
scope: {
ngModel: '='
},
template: '<div class="alert fade" bs-alert="ngModel"></div>',
link: function(scope, element, attrs) {
$timeout(function(){
element.hide();
}, 3000);
}
}
});
app.controller('AlertController', function($scope){
$scope.message = {
"type": "info",
"title": "Success!",
"content": "alert directive is working pretty well with 3 sec timeout"
};
$scope.alerts = [];
$scope.addAlert = function(index) {
$scope.alerts.push(
{
"type": "info",
"title": "Success!" + index,
"content": "alert " + index + " directive is working pretty well with 3 sec timeout"
}
)
}
});