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 渣 ...
随机推荐
- web10 动态action的应用
电影网站:www.aikan66.com 项目网站:www.aikan66.com游戏网站:www.aikan66.com图片网站:www.aikan66.com书籍网站:www.aikan66.co ...
- 自学iOS-获取当前时间
NSDate * senddate=[NSDate date]; NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; [dat ...
- 在WPF里实现计算器软件
一.具体代码 类代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; us ...
- 搭建zabbix详细步骤
关闭selinux和防火墙 selinux关闭: 1 命令查看出selinux的状态sestatus -v2 临时关闭 selinuxsetenforce 03 永久关闭selinuxvi /etc/ ...
- ERROR 1698 (28000): Access denied for user 'root'@'localhost' 解决方法
之前MySQL服务端本机上使用密码登陆root账号是没有问题的,但是今天不知道是因为动了哪里,登陆失败并有这个错误代码: ~$ mysql -u root -p Enter password: ERR ...
- [日常工作] SQLSERVER 数据库出问题..搜索到的有用的网页信息
Finding a table name from a page ID By: Paul Randal Posted on: September 25, 2014 1:42 am (Check o ...
- SQL中字符串截取、连接、替换等函数的用法
一.SQL中SUBSTRING函数的用法1.功能:返回字符.二进制.文本或图像表达式的一部分2.语法:SUBSTRING ( expression, start, length )3.QL 中的 su ...
- php curl常用的5个例子
转载:http://www.jb100.net/html/content-22-821-1.html php curl常用的5个例子 我用php ,curl主要是抓取数据,当然我们可以用其他的方法 ...
- 解决还原数据库是出现system.data.sqlclient.sqlerror filestream功能被禁用的问题
在master数据库下新建查询 输入如下语句: USE master GO RECONFIGURE 执行 成功还原数据库
- centOS基本操作和命令(更新)
1.文字输入和图形界面切换 CTRL+ALT+(F1~F6)为切换至文字输入,分别对应六个不同输入界面,可用以不同账号:CTRL+ALT+F7为切换至图形界面 2.修改时区 date -R date ...