Angular常用功能

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>

  

原文地址:https://www.cnblogs.com/SmileCN/p/3425063.html