Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I have this code in javascript

$scope.sample = function(){
    console.log(document.getElementById('foo'+modelId));
}

which returns false due to the HTML not yet complete rendering the page. See below:

<li ng-repeat="item in items" >
<input ng-model='foo'{{item.modelId}}
</li>

I want to avoid using timeout, is there a way to assure the HTML is completely rendered before executing the code.

share|improve this question

1 Answer 1

I think that the best way is to listen to scope.$last event and than run any code you need.

Here is an example:

angular.module('myApp', [])
.directive('repeatFinished', function() {
    return function(scope, element, attrs) {
        if (scope.$last) { // Here we can see that all ng-repeat items rendered
            scope.$eval(attrs.repeatFinished);
        }
    }
});

And than on your html you simple add:

<li ng-repeat="item in items"  repeat-finished="sample()">
//....
</li>
share|improve this answer
    
Hey thanks, I've searched similar problems to mine and they've also suggested listening to the last item. Thanks! – user3770093 Sep 30 at 2:36
    
stackoverflow.com/questions/15207788/… this thread provides a better understanding. – user3770093 Sep 30 at 5:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.