.directive(‘expander‘, function() { /* expander() restrict: E,A,C,M(元素,属性,样式,注释) transclude:true替换 compile(编译)和link(连接) <expander class=‘expander‘ expander-title=‘title‘></expander> */ var scope ={title : ‘=expanderTitle‘}; var template = ‘<div><div class="title" ng-click="toggle()">{{title}}</div><div class="body" ng-show="showMe" ng-transclude></div></div>‘; var link = function(scope, element, attrs){ scope.showMe = false; scope.toggle = function toggle() { scope.showMe = !scope.showMe; } } return { restrict : ‘EA‘, replace : true, transclude : true, scope : scope, template : template, link : link // link : function(scope, element, attrs) {} } })
时间: 2024-10-27 06:07:10