Created
December 17, 2012 00:30
-
-
Save jrmoran/4314600 to your computer and use it in GitHub Desktop.
AngularJS. Run a function from a directive's controller when ngRepeat is done evaluating an expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('app', []); | |
app.controller('ctrl', function($scope){ | |
$scope.images = [ {name: 'test1'}, {name: 'test2'}, | |
{name: 'test3'}, {name: 'test4'}]; | |
}); | |
app.directive('gallery',function() { | |
return { | |
restrict : 'C', | |
controller: function($scope, $element, $attrs){ | |
$scope.done = function(){ | |
console.log($element.find('li')); | |
}; | |
}, | |
link : function postLink(scope, iElement, iAttrs) { | |
} | |
}; | |
}); | |
app.directive('repeatDone', function($parse){ | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs){ | |
if(scope.$last){ | |
var fun = $parse(attrs.repeatDone); | |
fun(scope)(); | |
} | |
} | |
}; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body ng-app='app'> | |
<div ng-controller='ctrl'> | |
<ul id="myUl" class="gallery unstyled"> | |
<li ng-repeat="i in images" repeat-done='done'> | |
{{i}} | |
</li> | |
</ul> | |
</div> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment