I am trying to get the length of span element using angular.element
However, I realize that it takes time to load angular to execute ng-repeat
. And because of that, I didn't get the right number of length to return.
What I want to accomplish is: first, display number of zero based on the length of the letter. And then randomly generate a number to 0 to 9. Eventually, replace the number with the correct position of the letters.
HTML file
<span class="nbr" ng-repeat="(key, value) in letters track by $index">0</span>
JS File
app.controller('MainCtrl', function($scope) {
$scope.letters = ["H", "E","L", "L","O"];
$scope.randomnbr = angular.element(document.querySelectorAll('.nbr'));
alert($scope.randomnbr.length);
});
I made a Plunker Plunker Link
Will be helpful if someone can explain how and when angular is loaded and why this is happened. Thank you advanced!