Using Angularjs to realize Bootstrap's "accordion"

Source: Internet
Author: User

Main Page code (found the bootstrap official online accordion instance style has the problem, here still uses the 3.0.~ version)

<!DOCTYPE HTML><HTMLNg-app= "ct"><HeadLang= "en">    <MetaCharSet= "UTF-8">    <title></title>    <Linkrel= "stylesheet"href= "Bootstrap-3.3.4-dist/css/bootstrap.css"/>    <Linkrel= "stylesheet"href= "Bootstrap-3.3.4-dist/css/bootstrap-r.css"/></Head><Body><HR><Divclass= "Container"Ng-controller= "C1">    <Kittencup-group>        <Kittencup-collapseng-repeat= "collapse in Data"Head= "Collapse.a">            <spanNg-bind= "collapse.b"></span>        </Kittencup-collapse>    </Kittencup-group></Div></Body><Scriptsrc=".. /angular.js "></Script><Script>    varapp=Angular.module ("CT",[]); App.factory ("Data",function(){         return[{A:"wrong, your sister.", B:"Contents1"}, {a:"Title2", B:"contents2"             }         ]     }); App.controller ("C1",['$scope','Data', function($scope, Data) {//load data from Ctrl to view$scope. Data=Data;    }]); App.directive ('Kittencupgroup', function(){         return{restrict:"EA", transclude:true, replace:true, Template:"<div class= ' panel-group ' ng-transclude></div>", Controller:function(){                  This. Collapsegroup= [];  This. Otherclose= function(currcollaps) {Angular.foreach ( This. Collapsegroup,function(collaps) {if(Collaps!==currcollaps) {Collaps.isopen= true;                 }                     });    }             }         }    }); App.directive ('Kittencupcollapse', function(){        return{restrict:"EA", require:"^kittencupgroup", replace:true, Templateurl:"templates/contents.html", transclude:true, scope:{head:"="}, Link:function(scope, elements, Attrs, Superctrl) {Scope.isopen= true; Scope.open= function() {Scope.isopen= !Scope.isopen;                Superctrl.otherclose (scope);                };            SuperCtrl.collapseGroup.push (scope); }        }    });</Script></HTML>

Template code:

<Divclass= "Panel Panel-default">    <Divclass= "Panel-heading"Ng-click= "open ()">        <h4class= "Panel-title">            <ahref= "#collapseOne">                <spanNg-bind= "Head"></span>            </a>        </h4>    </Div>    <Divclass= "Panel-collapse"Ng-class= "{Collapse:isopen}">        <Divclass= "Panel-body"Ng-transclude>        </Div>    </Div></Div>

Using Angularjs to realize Bootstrap's "accordion"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.