为了账号安全,请及时绑定邮箱和手机立即绑定

教程里的Accordion实例问题

教程里的Accordion实例问题

chun2 2016-04-14 17:32:49
<html ng-app="expanderModule"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="Accordion.css"/> <script src="framework/angular-1.3.0.14/angular.js"></script> <script src="Accordion.js"></script> </head> <body ng-controller='SomeController' > <accordion> <expander class='expander' ng-repeat='expander in expanders' expander-title='expander.title'> {{expander.text}} </expander> </accordion> </body></html>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 : 'Click me to expand', text : 'Hi there folks, I am the content that was hidden but is now shown.' }, { title : 'Click this', text : 'I am even better text than you have seen previously' }, { title : 'Test', text : 'test' }];});上面代码中加粗下划线的代码是否没有作用啊,我去掉后效果还是一样的啊,但是教程的案例里为什么要写这2段代码有什么意义?求解答
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1332 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信