如何使用循环遍历角度$ scope变量

Sor*_*rer 24 scope angularjs angularjs-scope

我想用这样的for循环迭代$ scope变量.在这个例子中$范围对象包括对象账户 计有5个对象,其名称是从1到5编号他们每个人都有一个名称.

for(var i = 1; i < 5; i++){
   $('#name').val($scope.accounts.i.name);
}
Run Code Online (Sandbox Code Playgroud)

问题: $ scope.accounts.i不确定的,因为我不会因为内部varibale算$范围变量.它被视为字母i,因此我认为没有机会使用for循环遍历范围.当我在$ scope变量周围使用""时,它将只显示为普通html,而angular不会被解释.

Aja*_*wal 45

上面做的角度方式是

 $scope.accounts=[{name:"123"},{name:"124"},{name:"125"}]

            angular.forEach($scope.accounts,function(value,index){
                alert(value.name);
            })
Run Code Online (Sandbox Code Playgroud)