Skip to content Skip to sidebar Skip to footer

Function Executed More Times Than Expected

Here's a short Angular app: angular.module('AppName', []) .controller('TwoController', function($scope){ var oneArray = ['1','2']; $scope.secondArray = []; for (i in oneArray){ $

Solution 1:

This is because for..in loops on properties and Array have the property length too and another one that make it loop another time. IUf you want to see it just do console.log(i)

Either use a angular.forEach or the old for(var i = 0; i < ...)

EDIT : failed answer : The reason is because of angular.

He will go through the list twice : once at init and once at the end of his loop to check for changes

Solution 2:

Seems like the view just gets rendered twice, so i don't think you have a real problem...

Post a Comment for "Function Executed More Times Than Expected"