angularjs中的数组长度返回undefined

时间:2020-12-27 21:43:19

JS:

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.

在前端,我有一个很好的用户列表。但是,当我检索长度时,我得到了未定义。为什么?我需要用户的长度来遍历对象数组。

3 个解决方案

#1


117  

use:

使用:

$scope.users.length;

Instead of:

代替:

$scope.users.lenght;

And next time "spell-check" your code.

下次“拼写检查”你的代码。

#2


0  

Make it like this:

像这样:

$scope.users.data.length;

#3


-1  

var leg= $scope.name.length;
$log.info(leg);

#1


117  

use:

使用:

$scope.users.length;

Instead of:

代替:

$scope.users.lenght;

And next time "spell-check" your code.

下次“拼写检查”你的代码。

#2


0  

Make it like this:

像这样:

$scope.users.data.length;

#3


-1  

var leg= $scope.name.length;
$log.info(leg);