How to iterate through angular $scope variables with a loop

后端 未结 2 533
深忆病人
深忆病人 2020-12-29 05:22

I want to iterate through $scope variables with a for loop like this. In this example the $scope object includes an object accounts inlcuding 5 objects, whose name

相关标签:
2条回答
  • 2020-12-29 05:59

    Angular way to do above is

     $scope.accounts=[{name:"123"},{name:"124"},{name:"125"}]
    
                angular.forEach($scope.accounts,function(value,index){
                    alert(value.name);
                })
    
    0 讨论(0)
  • 2020-12-29 06:02

    If accounts is an array, you can use the array indexer:

    for(var i = 1; i < 5; i++){
       $('#name').val($scope.accounts[i].name);
    }
    
    0 讨论(0)
提交回复
热议问题