3 回答
肥皂起泡泡
TA贡献1829条经验 获得超6个赞
$index, $first, $middle$last
<div ng-controller="Ctrl" my-main-directive>
<div ng-repeat="thing in things" my-repeat-directive>
thing {{thing}} </div></div>angular.module('myApp', []).directive('myRepeatDirective', function() {
return function(scope, element, attrs) {
angular.element(element).css('color','blue');
if (scope.$last){
window.alert("im the last!");
}
};}).directive('myMainDirective', function() {
return function(scope, element, attrs) {
angular.element(element).css('border','5px solid red');
};});
拉丁的传说
TA贡献1789条经验 获得超8个赞
<div ng-controller="Ctrl">
<div class="thing" ng-repeat="thing in things" my-post-repeat-directive>
thing {{thing}} </div></div>function Ctrl($scope) {
$scope.things = [
'A', 'B', 'C'
];}angular.module('myApp', []).directive('myPostRepeatDirective', function() {
return function(scope, element, attrs) {
if (scope.$last){
// iteration is complete, do whatever post-processing
// is necessary
element.parent().css('border', '1px solid black');
}
};});
莫回无
TA贡献1865条经验 获得超7个赞
ng-repeat
ng-init
<div ng-repeat="thing in things" ng-init="$last && finished()">
$lastfinished
$scope.finished
finished
<div style="display:none" ng-init="things.length < 1 && finished()"></div>//or<div ng-if="things.length > 0" ng-init="finished()"></div>
ng-repeat
<div ng-if="things.length > 0" ng-init="finished()"></div><div ng-repeat="thing in things" ng-init="$last && finished()">
添加回答
举报
0/150
提交
取消
