I'm working on a schoolproject. I created some lines with ng-repeat. Now when I want to add them with 'addElementsByClassName' the arraylength will still be 0.
This is in my html:
<tr class = "ingredient" ng-repeat = "i in data.Ingredients">
<td>{{ i.Ingredient.Name }}</td>
<td>{{ i.Ingredient.Amount_g }}</td>
</tr>
This is in my controller:
$scope.allIngredients = [];
$scope.dashboard = MainService.getDashboard ();
$scope.dashboard.then (function (data) { //receive the data from a server via MainService
$scope.data = data;
$scope.allIngredientRows = document.getElementsByClassName ('ingredient');
console.log ($scope.allIngredients.length);
});
I want my rows inside that array so I can do something with them later. But now the length of the array remains 0.
You are not giving the Angular digest cycle any time to run.
Try retrieving the row count right before that 'later' use. It should be updated. If not, try using $scope.$$apply() to induce a digest cycle.