我使用
Angular UI Bootstrap生成警报框,使用以下代码:
<alert data-ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</alert>
它按预期呈现:
我的问题是:是否有某种方法可以将某些通知关闭,而其他通知则根据变量?
我编写了这个模拟代码,并且只在closeable为true时才显示可关闭的x.
$scope.alerts = [ { type: 'danger',closeable: false,msg: 'Oh snap! Change a few things up and try submitting again.' },{ type: 'success',closeable: true,msg: 'Well done! You successfully read this important alert message.' },{ type: 'warning',msg: 'Be careful! Something may go wrong here.' },{ type: 'info',msg: 'Attention! Here is some news for you.' } ];
解决方法
试试你的十字架
<button type="button" class="close" data-dismiss="alert" ng-if="alert.closable"> <span aria-hidden="true">× </span><span class="sr-only">Close</span></button>