Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array length in angularjs returns undefined

Tags:

angularjs

JS:

function UserController($scope, User, Group){

    $scope.users = User.query();

    $scope.isNewUser = function(){

            var len = $scope.users.lenght;
            console.log(len); //undefined

            for(var i = 0; i < len; i++){
                if($scope.users[i].created_at == null){
                    return false;
                }
            }

            return true;
        }
    }
}

In frontend I have a list of users that are rendered well. However when I retrieve the length I get undefined. Why? I need the length of users to loop through the array of objects.

like image 413
UpCat Avatar asked Apr 20 '13 19:04

UpCat


1 Answers

use:

$scope.users.length;

Instead of:

$scope.users.lenght;

And next time "spell-check" your code.

like image 55
Yair Nevet Avatar answered Oct 11 '22 23:10

Yair Nevet