<!DOCTYPE html>
<html ng-app="my_app">
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module("my_app", []);
app.controller('my_controller', function($scope) {
$scope.students = [{
studentno: 's001',
studentname: '学生1',
address: '浙江',
},
{
studentno: 's002',
studentname: '学生2',
address: '浙江',
},
{
studentno: 's003',
studentname: '学生3',
address: '浙江',
},
];
$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
console.log(document.getElementsByClassName('studentno').length);
});
});
app.directive('repeatFinish', function($timeout) {
return {
link: function(scope, element, attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit('ngRepeatFinished');
});
}
}
}
});
</script>
</head>
<body ng-controller="my_controller">
<div>
<ul>
<li ng-repeat="item in students" repeat-finish>
<span class="studentno">{{item.studentno}}</span>
<span class="studentname">{{item.studentname}}</span>
<span class="address">{{item.address}}</span>
</li>
</ul>
</div>
</body>
</html>