angular 指令封装弹出框效果
就直接用bs的警告框啦~,Duang~
功能
可以设置message和type,type就是bs内置的几种颜色
默认提示3秒框自动关闭,或者点击x号关闭
代码
模板
<div class="alert alert-{{type || 'info'}}" ng-show="message">
<button type="button" class="close" ng-click="hideAlert()">
<span class="glyphicon glyphicon-remove"></span>
</button>
{{message}}
</div>
指令
/**
* 提示框
*/
commonToolDirectives.directive('alertBar',[function(){
return {
restrict: 'EA',
templateUrl: 'src/common/views/alertBar.html',
scope : {
message : "=",
type : "="
},
link: function(scope, element, attrs){
scope.hideAlert = function() {
scope.message = null;
scope.type = null;
};
}
};
}]);
服务
/**
* 提示框数据
*/
commonServices.factory('TipService', ['$timeout', function($timeout) {
return {
message : null,
type : null,
setMessage : function(msg,type){
this.message = msg;
this.type = type;
//提示框显示最多3秒消失
var _self = this;
$timeout(function(){
_self.clear();
},3000);
},
clear : function(){
this.message = null;
this.type = null;
}
};
}]);
用法
因为是全局提示,所以就只有一个,在
index.html中添加:<!--全局提示框-->
<alert-bar class="alert_bar" message="tipService.message" type="tipService.type"></alert-bar>同时保证他的
z-index最高然后因为需要在页面上直接访问tipService,需要在最外层
controller(如果没有可以直接绑定到$rootScope)中绑定://提示信息服务
$scope.tipService = TipService;调用的时候在c中直接设置message和type就可以了
TipService.setMessage('登录成功', 'success');当然从上面的模板代码可以看到,如果不传第二个参数,type默认是info,也就是那个蓝色的
效果
我的效果就是这样啦~
angular 指令封装弹出框效果的更多相关文章
- Javascript封装弹出框控件
1.首先先定义好弹出框的HTML结构 <div class="g-dialog-contianer"> <div class="dialog-windo ...
- JQuery+CSS3实现封装弹出登录框效果
原文:JQuery+CSS3实现封装弹出登录框效果 上次发了一篇使用Javascript来实现弹出层的效果,这次刚好用了JQuery来实现,所以顺便记录一下: 因为这次使用了Bootstrap来做一个 ...
- 代码录播:jQueryMobile 实现一个简单的弹出框效果
今天给大家带来的是 jQueryMobile 实现一个简单的弹出框效果,有兴趣的童鞋可以试试哦~ ^_^ 阅读原文:www.gbtags.com
- Bootboxjs快速制作Bootstrap的弹出框效果
Bootboxjs是一个简单的js库,简单快捷帮你制作一个Bootstrap的弹出框效果. 一.简介 bootbox.js是一个小的JavaScript库,它帮助您在使用bootstrap框架的时候快 ...
- jquery 弹出框效果
html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- Android仿ios底部弹出框效果
准备: public class ActionSheet { public interface OnActionSheetSelected { void onClick(int whichButton ...
- bootstrap中popover.js(弹出框)使用总结+案例
bootstrap中popover.js(弹出框)使用总结+案例 *转载请注明出处: 作者:willingtolove: http://www.cnblogs.com/willingtolove/p/ ...
- 控制非模态弹出框(showModelessDialog)唯一且随父页面关闭
网站开发中,常常会遇到需要弹出窗体的情况,一般弹出框有模态和非模态两种,如下: 模态:window.showModalDialog() 非模态:window.showModelessDialog() ...
- 弹出框插件layer使用
layer是一款近年来备受青睐的web弹层组件,她具备全方位的解决方案,致力于服务各水平段的开发人员,您的页面会轻松地拥有丰富友好的操作体验. 插件官方地址:http://layer.layui.co ...
随机推荐
- HDU——1596find the safest road(邻接矩阵+优先队列SPFA)
find the safest road Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- C++ 错误解决 —— internal compiler error
问题: g++ 编译时,报错: g++: internal compiler error: Killed (program cc1plus) 出错原因: 出错的原因是(虚拟机)运行内存不足,而大量te ...
- python 字体颜色,背景颜色
- ecs01初始化node环境
npm install 报错 > uglifyjs-webpack-plugin@ postinstall /opt/apps/iview-admin/node_modules/webpack/ ...
- poj 1418 Viva Confetti
Viva Confetti Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1025 Accepted: 422 Desc ...
- jQuery控件之分页控件-- kkpager v1.3使用简介
js分页展示控件,传入简单参数就能使用的分页效果控件 在线测试链接: http://pgkk.github.io/kkpager/example/pager_test.html http://pgkk ...
- net3:DropDownList的动态绑定
原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System.Data;using System.Configuration;using System ...
- Notepad++中常用的插件【转】
转自:http://www.crifan.com/files/doc/docbook/rec_soft_npp/release/htmls/npp_common_plugins.html 1.4. N ...
- 電池的標稱電壓 與 power consumption 量測
電池標稱電壓 定義如下圖, 以25度為例,20度再往上點, 4V 放一下電就往下掉, 3V 放一下電就往下掉, 假設 3.8V 是擁有最多 capacity 可以 discharge 的電壓,放電放了 ...
- 小程序-引用其他js文件
我也是小白菜,之所以有这个记录是因为我做项目时遇到了这个问题 流程: 1.需要建立一个js文件 content.js function myContent() { console.log(&quo ...