bootstrap-switch与angularjs结合使用
bootstrap-switch和angularjs结合使用
由于angularjs的dom操作总是先执行,导致$(input[name="switch"])找不到元素,所以使用directive自定义指令,有两种方法:
html部分:
<my-input power="{{x.power}}" did="{{x.id}}"></my-input>
directive指令部分:
1、通过插入元素的方法
app.directive('myInput',function(factoryName){
return{
restrict : "AE",
scope : {
power :"@",
did : "@"
},
template :'<div class="switch"></div>',
replace : true,
link : function(scope,element,attr){
var $input = $('<input type="checkbox" name="switch" checked>');
$(element[]).append($input);
$(element[]).children().bootstrapSwitch({
'size':'small',
onSwitchChange : function(target,state){
//state是开关的状态
}
})
}
}
})
2、通过引入外部文件的方法
return{
template : '<div ng-include="getElement()"></div>',
scope : {
dtype : '@',
id : '@'
},
replace : true,
link : function(scope,element,attr){
scope.getElement = function(){
if(attr.dtype == 3){
return 'testchecked.html';
}else{
return 'testunchecked.html';
}
};
}
}
外部文件testchecked.html为
<div class="switch" data-on="info" data-off="success">
<input type="checkbox" name="switch" checked/>
</div>
<script type="text/javascript">
$("input[name='switch']").bootstrapSwitch({
'size' : 'normal',
'onColor':'info',
'onSwitchChange':function(target,state){ }
})
</script>
bootstrap-switch与angularjs结合使用的更多相关文章
- bootstrap switch功能
bootstrap switch是一个按钮开关,点击时获取其状态可通过以下代码: <input id="email_switch_state" type="chec ...
- 前端插件之Bootstrap Switch 选择框开关控制
简介 Bootstrap Switch是一款轻量级插件,可以给选择框设置类似于开关的样式 它是依赖于Bootstrap的一款插件 下载 下载地址 在线引用 导入 因为它是依赖于Bootstrap的一款 ...
- bootstrap switch样式修改与多列等间距布局
先以一张图开启今天的随笔 今天实习遇到了switch按钮,小姐姐说用插件bootstrap switch来写,我第一次用这个插件,首先在引入方面就遇到了很多坑,先来总结一下bootstrap swit ...
- 前端基础(十):Bootstrap Switch 选择框开关控制
简介 Bootstrap Switch是一款轻量级插件,可以给选择框设置类似于开关的样式 它是依赖于Bootstrap的一款插件 下载 下载地址 在线引用 导入 因为它是依赖于Bootstrap的一款 ...
- 使用jQuery获取Bootstrap Switch的值
$('#switcher').bootstrapSwitch('state'); // true || false $('#switcher').bootstrapSwitch('toggleStat ...
- bootstrap Switch 的一个坑点
在bootstrap的modal点开的时候改变bootstrapSwitch的状态的时候,会出现第一次打开modal,switch没有变化,第二次以后打开modal才会改变,这个问题找了好久没有找到答 ...
- bootstrap tooltips在 angularJS中的使用
使用bootstrap自带的提示控件,省去了不少事情 <div class="s2" ng-init="InitTooltip()"> <in ...
- Bootstrap switch 切换状态踩坑
Boostrap switch 下载地址(http://www.bootcss.com/p/bootstrap-switch/),同时配有一些简单的用例. 其中写到 Toggle State切换状态的 ...
- AngularJS 参考手册
AngularJS 参考手册 AngularJS 指令 本教程用到的 AngularJS 指令 : 指令 描述 ng-app 定义应用程序的根元素. ng-bind 绑定 HTML 元素到应用程序数据 ...
- [译]用AngularJS构建大型ASP.NET单页应用(一)
原文地址:http://www.codeproject.com/Articles/808213/Developing-a-Large-Scale-Application-with-a-Single 渣 ...
随机推荐
- POJ 2151 Check the difficulty of problems 概率dp+01背包
题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit ...
- hihocoder #1388 : Periodic Signal fft
题目链接: https://hihocoder.com/problemset/problem/1388 Periodic Signal 时间限制:5000ms内存限制:256MB 问题描述 Profe ...
- 【CS231N】3、Softmax分类器
wiki百科:softmax函数的本质就是将一个K维的任意实数向量压缩(映射)成另一个K维的实数向量,其中向量中的每个元素取值都介于(0,1)之间. 一.疑问 二.知识点 1. softmax函数公式 ...
- 001_JavaWeb之Servlet的路径映射问题
001_JavaWeb之Servlet的路径映射问题 在web.xml中写入: <servlet> <servlet-name>DeleteStudent</servle ...
- Mac 下搭建 Apache 服务器
Apache作为最流行的Web服务器端软件之一,它的优点与地位不言而喻.下面介绍下在Mac下搭建Apache服务器的步骤: (1)“前往” –>”个人” (2)在你的个人目录下新建一个文件夹,改 ...
- iOS- 多线程中如何去保证线程安全
一.前言 前段时间看了几个开源项目,发现他们保持线程同步的方式各不相同,有@synchronized.NSLock.dispatch_semaphore.NSCondition.pthread_mut ...
- ssh结合使用
springxml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=& ...
- jmeter 多线程组间变量共享
jmeter的线程组之间是相互独立的,各个线程组互不影响,所以线程组A中输出的参数,是无法直接在线程组B中被调用的. 但是有时为了方便管理,我们可能是把各个接口单独存放在不同的线程组中.拿Cookie ...
- [转帖]Ubuntu 安装VNC的一个方法
来源: https://blog.csdn.net/CSDN_duomaomao/article/details/75270271 Ubuntu 16.04 LTS 安装VNC,在百度和谷歌找了很多教 ...
- Delphi 判断一个字符串是否为数字
//函 数 名: IsDigit//返 回 值: boolean//日 期:2011-03-01//参 数: String//功 能: 判断一个字符串是否为数字// ...