Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created December 17, 2012 00:30
Show Gist options
  • Save jrmoran/4314600 to your computer and use it in GitHub Desktop.
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
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)();
}
}
};
});
<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