首先来看看效果
实现这样的效果,必须使用指令了,只有使用指令才能单独控制每一个scope。
示例代码如下:
<div class="form-group"> <label class="col-sm-2 control-label">请选择文章主题色彩</label> <div class="col-sm-10" theme-group> <label class="i-switch m-t-xs m-r"> <input type="checkbox" input-theme > <i></i> </label> <label class="i-switch bg-info m-t-xs m-r"> <input type="checkbox" input-theme> <i></i> </label> <label class="i-switch bg-primary m-t-xs m-r"> <input type="checkbox" input-theme > <i></i> </label> <label class="i-switch bg-danger m-t-xs m-r"> <input type="checkbox" input-theme> <i></i> </label> </div> </div>
(function () { angular .module("shishuoproject") .directive("themeGroup",function(){ return{ controller: function () { var scopeArray=[]; this.addScope= function (scope) { var self=this; scopeArray.push(scope); scope.$on("$destory",function(){ self.removeScope(scope); }) }; this.closeScope= function (scope) { //var l=scopeArray.length; angular.forEach(scopeArray, function (value) { if(value!=scope){ value.flag=false; } }) }; this.removeScope= function (scope) { var index=scopeArray.indexOf(scope); if(index!==-1){ scopeArray.splice(index,1); } }; this.getIndex= function (scope) { var index=scopeArray.indexOf(scope); return index; } } } }) .directive("inputTheme",function(){ return{ restrict:'EA', require:"^", template:'<input type="checkbox" ng-click="choseTheme()" ng-model="flag">', replace:true, scope:{}, link: function (scope,element,attr,themeCon) { var colorArray=['#27c24c','#23b7e5','#7266ba',' #f05050']; themeCon.addScope(scope); scope.choseTheme= function () { themeCon.closeScope(scope); var index=themeCon.getIndex(scope); var color=colorArray[index]; scope.$emit("getArticleThemeColor",{'color':color}); console.log(scope.flag); }; } } }) })()
这里简单说一下,实现的主要思想就是,通过指令单独生成scope,每一个指令都是一个单独的scope,这样每个ng-modal都独立出来了,然后通过继承一个总的指令来实现控制。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者使用Angular.js能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 范文芳.1996-FNNTASY【HYPE】【WAV+CUE】
- 纯音入心系列纯音乐《韵味古筝曲》1CD[MP3][146.2MB]
- 纯音入心系列纯音乐《古筝系列-传统乐曲》1CD[MP3][974.7MB]
- 纯音入心系列纯音乐《古筝系列-弦凝指咽声停处》1CD[MP3][656.5MB]
- 群星.1994-大烂片2辑【派森】【WAV+CUE】
- 吴倩莲.1997-望爱【EMI百代】【WAV+CUE】
- 杨千嬅.2002-万紫千红演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郭采洁.2015-Begin.Again爱造飞鸡【华纳】【FLAC分轨】
- 许志安.2011-ON.AND.ON【东亚】【WAV+CUE】
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]