AngularJS折疊菜單實現(xiàn)方法示例
本文實例講述了AngularJS折疊菜單實現(xiàn)方法。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="bootstrap.min.css" rel="external nofollow" >
<script src="jquery.min.js"></script>
<script src="angular.min.js"></script>
<script src="bootstrap.min.js"></script>
<script type="text/javascript">
var expModule=angular.module('expanderModule',[])
expModule.directive('accordion', function() {
return {
restrict : 'EA',
replace : true,
transclude : true,
template : '<div ng-transclude></div>',
controller : function() {
var expanders = [];
this.gotOpened = function(selectedExpander) {
angular.forEach(expanders, function(expander) {
if (selectedExpander != expander) {
expander.showMe = false;
}
});
}
this.addExpander = function(expander) {
expanders.push(expander);
}
}
}
});
expModule.directive('expander', function() {
return {
restrict : 'EA',
replace : true,
transclude : true,
require : '^?accordion',
scope : {
title : '=expanderTitle'
},
template : '<div>'
+ '<div class="title" ng-click="toggle()">{{title}}</div>'
+ '<div class="body" ng-show="showMe" ng-transclude></div>'
+ '</div>',
link : function(scope, element, attrs, accordionController) {
scope.showMe = false;
accordionController.addExpander(scope);
scope.toggle = function toggle() {
scope.showMe = !scope.showMe;
accordionController.gotOpened(scope);
}
}
}
});
expModule.controller("SomeController",function($scope) {
$scope.expanders = [{
title : '1',
text : '1.1.'
}, {
title : '2',
text : '2.2'
}, {
title : '3',
text : '3.3'
}];
});
</script>
<style type="text/css">
.expander {
border: 1px solid black;
width: 250px;
}
.expander>.title {
background-color: black;
color: white;
padding: .1em .3em;
cursor: pointer;
}
.expander>.body {
padding: .1em .3em;
}
</style>
</head>
<body ng-app="expanderModule" ng-controller='SomeController'>
<accordion>
<expander class='expander' ng-repeat='expander in expanders' expander-title='expander.title'>
{{expander.text}}
</expander>
</accordion>
</body>
</html>
更多關(guān)于AngularJS相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《AngularJS指令操作技巧總結(jié)》、《AngularJS入門與進階教程》及《AngularJS MVC架構(gòu)總結(jié)》
希望本文所述對大家AngularJS程序設(shè)計有所幫助。
- AngularJS實現(xiàn)樹形結(jié)構(gòu)(ztree)菜單示例代碼
- 實例詳解AngularJS實現(xiàn)無限級聯(lián)動菜單
- AngularJS實現(xiàn)的select二級聯(lián)動下拉菜單功能示例
- Angular.js與Bootstrap相結(jié)合實現(xiàn)手風琴菜單代碼
- AngularJS動態(tài)菜單操作指令
- AngularJS+Bootstrap3多級導(dǎo)航菜單的實現(xiàn)代碼
- AngularJS模糊查詢功能實現(xiàn)代碼(過濾內(nèi)容下拉菜單排序過濾敏感字符驗證判斷后添加表格信息)
- Angular.JS實現(xiàn)無限級的聯(lián)動菜單(使用demo)
- angularjs+bootstrap菜單的使用示例代碼
- Angluar+zorro實現(xiàn)無限級菜單
相關(guān)文章
AngularJs Understanding the Model Component
本文主要介紹AngularJs Understanding the Model Component的內(nèi)容,這里整理了相關(guān)資料,并詳細講解了這部分知識,有興趣的小伙伴可以參考下2016-09-09
AngularJS基礎(chǔ) ng-submit 指令簡單示例
本文主要介紹AngularJS ng-submit 指令,這里對ng-submit 指令的基礎(chǔ)資料做了詳細介紹整理,并附有代碼示例,有需要的小伙伴可以參考下2016-08-08
AngularJs學(xué)習第八篇 過濾器filter創(chuàng)建
這篇文章主要介紹了AngularJs學(xué)習第八篇 過濾器filter創(chuàng)建的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-06-06
Angularjs中$http以post請求通過消息體傳遞參數(shù)的實現(xiàn)方法
這篇文章主要介紹了Angularjs中$http以post請求通過消息體傳遞參數(shù)的方法,結(jié)合實例形式分析了$http使用post請求傳遞參數(shù)的相關(guān)設(shè)置與使用技巧,需要的朋友可以參考下2016-08-08
AngularJS實現(xiàn)在ng-Options加上index的解決方法
這篇文章主要介紹了AngularJS實現(xiàn)在ng-Options加上index的解決方法,結(jié)合實例形式分析了AngularJS在ngOptions添加索引的操作步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2016-11-11

