码迷,mamicode.com
首页 > 其他好文 > 详细

accordion

时间:2017-10-19 16:03:29      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:char   cto   doctype   sheet   seo   logs   default   ras   index   

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">

</head>
<body>

<div ng-app="myApp">

     <div class="container">
         <div ng-controller="firstController">
             <kittencup-group>
                 <kittencup-collapse  ng-repeat="collapse in data"  heading="{{collapse.title}}">{{collapse.content}}</kittencup-collapse>
             </kittencup-group>


         </div>

     </div>

</div>
<script type="text/javascript" src="../vendor/angularjs.js"></script>
<script type="text/javascript" src="app/index.js"></script>

</body>
</html>

<div class="panel panel-default">
        <div class="panel-heading" ng-click="changeOpen()">
            <h4 class="panel-title">
                <a href="#">
                    {{heading}}
                </a>
            </h4>
        </div>
        <div class="panel-collapse" ng-class="{collapse:isOpen}">
            <div class="panel-body" ng-transclude>

            </div>
        </div>
</div>

  

angular.module(‘myApp‘,[])
    //数据
 .factory(‘Data‘,function () {
        return [
            {
                title:‘no1‘,
                content:‘no1-content‘
            },
            {
                title:‘no2‘,
                content:‘no2-content‘
            }, {
                title:‘no3‘,
                content:‘no3-content‘
            }
        ]
 })
.controller(‘firstController‘,[‘$scope‘,‘Data‘,function ($scope,Data) {
    $scope.data=Data;
}])
.directive(‘kittencupGroup‘,function () {
    return{
        restrict:‘E‘,
        replace:true,
        template:‘<div class="panel-grouup" ng-transclude></div>‘,
        transclude:true,
        controllerAs:‘kittencupGroupController‘,
        controller:function () {
            //console.log($scope);
            this.groups=[];
            this.closeOtherCollapse=function (nowScope) {
                angular.forEach(this.groups,function (scope) {
                    if(scope!==nowScope ){
                        scope.isOpen=true;
                    }
                })
            };
        }
    }
})
.directive(‘kittencupCollapse‘,function () {
    return{
        restrict:‘E‘,
        replace:true,
        require:‘^kittencupGroup‘,
        templateUrl:‘tmp/kittencupCollapse.html‘,
        scope:{
            heading:‘@‘
        },
        link:function (scope,element,attrs,kittencupGroupController) {
            //console.log(scope);
            scope.isOpen=true;
            scope.changeOpen=function () {
                scope.isOpen=!scope.isOpen;
                kittencupGroupController.closeOtherCollapse(scope);
            };
            kittencupGroupController.groups.push(scope);
        },
        transclude:true

    }
})

  

accordion

标签:char   cto   doctype   sheet   seo   logs   default   ras   index   

原文地址:http://www.cnblogs.com/zhuj/p/7692703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!