问题描述
我正在尝试使用AngularJS Bootstrap警报,如所述,并带有 dismiss-超时属性。在此示例中它没有任何作用,警报只是定期显示而不会消失。
I'm trying to use AngularJS Bootstrap alerts like explained here with the "dismiss-on-timeout" attribute. It has no effect in this example, the alert just appears regularly and doesn't disappear.
<alert type="warning" dismiss-on-timeout="2000">Alert text</alert>
但是在站点的ng-repeat示例中它确实起作用:
It does however work in the ng-repeat example from the site:
<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)" dismiss-on-timeout="2000">{{alert.msg}}</alert>
问题是缺少close属性吗?如果是这样,您如何为不属于数组的警报编写关闭函数?
Is the problem the missing close attribute? If so, how do you write a close function for an alert that's not part of an array?
推荐答案
效果很好,它是只需 dismissOnTimeout
指令即可调用。该控制器依次使用外部作用域 close
方法。因此,您需要使用指令来实现它:
Well it works, it's just dismissOnTimeout
directive invokes close
method of the alert directive controller. This controller in its turn uses outer scope close
method. So you need to implement it with so that directive could call it:
<alert type="danger" close="closeAlert()" ng-if="show"
dismiss-on-timeout="2000">Something happened.</alert>
并在控制器中:
$scope.show = true;
$scope.closeAlert = function(index) {
$scope.show = false;
};
这篇关于AngularJS Bootstrap警报超时超时关闭不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!