AngularJS Bootstrap 警报解除超时属性不起作用 [英] AngularJS Bootstrap alert dismiss-on-timeout attribute doesn't work

查看:26
本文介绍了AngularJS Bootstrap 警报解除超时属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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 方法.该控制器依次使用外部作用域 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 警报解除超时属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆