1.默认选择让第0个元素的class为active

ng-class="{active:$index == 0}"

 

2.指令的例子

<!DOCTYPE html>
<html ng-app="test">
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">

</style>
</head>
<body ng-controller="helloCtrl">


<expander class="expander" expander-title="title" expander-content="content"></expander>


<script src="scripts/lib/angular.min.js"></script>
<script>
angular.module('test',[])

.directive('expander',function (){

return {

restrict:'EA',
replace : true,
transclude : true,
scope : {

title : '=expanderTitle',
content : '=expanderContent'
},
template : '<div>'
+ '<div class="title" ng-click="toggle()">{{title}}</div>'
+ '<div class="body" ng-show="showMe">{{content}}</div>'
+ '</div>',

link : function (scope,element,attrs){

scope.showMe = false;
scope.toggle = function (){

scope.showMe = !scope.showMe;
}
}
}
})

.controller('helloCtrl',function ($scope){

$scope.title = '标题';
$scope.content = '内容';
})
</script>
</body>
</html>

  

Posted on 2013-11-15 11:54  SmileCN  阅读(293)  评论(0编辑  收藏  举报