AngularJS Bootstrap警报dismiss-on-timeout属性不起作用

栏目: CSS · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/32023558/angularjs-bootstrap-alert-dismiss-on-timeout-attribute-doesnt-work
我正在尝试使用AngularJS Bootstrap警报,如 here

解释的“dismiss-on-timeout”属性.它在此示例中没有任何效果,警报只是定期出现并且不会消失.

<alert type="warning" dismiss-on-timeout="2000">Alert text</alert>

但它确实在网站的ng-repeat示例中有效:

<alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)" dismiss-on-timeout="2000">{{alert.msg}}</alert>

问题是缺少关闭属性吗?如果是这样,你如何编写一个不属于数组的警报的close函数?

它工作正常,它只是dismissOnTimeout指令调用警报指令控制器的 close method

.该控制器依次使用外部范围关闭方法.所以你需要实现它,以便指令可以调用它:

<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;
};

翻译自:https://stackoverflow.com/questions/32023558/angularjs-bootstrap-alert-dismiss-on-timeout-attribute-doesnt-work


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

XForms Essentials

XForms Essentials

Micah Dubinko / O'Reilly Media, Inc. / 2003-08-27 / USD 29.95

The use of forms on the Web is so commonplace that most user interactions involve some type of form. XForms - a combination of XML and forms - offers a powerful alternative to HTML-based forms. By pro......一起来看看 《XForms Essentials》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器