如何在angularjs中迭代$scope变量
How to iteration on $scope variable in angularjs?
我有这样的代码:
$scope.maps = [
new google.maps.LatLng($scope.longitude[0], $scope.latitude[0]),
new google.maps.LatLng($scope.longitude[1], $scope.latitude[1]),
new google.maps.LatLng($scope.longitude[2], $scope.latitude[2])];
如何在AngularJS风格中进行简化以进行更多迭代?
$scope.maps = [];
$scope.longitude.forEach(function(el, i) {
$scope.maps.push(new google.maps.LatLng(el, $scope.latitude[i]));
});
// or
$scope.maps = [];
for(var i = 0; i < $scope.longitude.length; ++i) {
$scope.maps.push(new google.maps.LatLng($scope.longitude[i], $scope.latitude[i]));
}
只是为了澄清CodeiSir的答案。不是"Angular"迭代,他展示的是javascript。您也可以使用它来读取数据,就像您在html中使用angular ng repeat一样。
更多信息请点击此处
相关文章:
- $scope变量被视为字符串AngularJs
- $scope变量,ng隐藏/显示
- $Scope变量在HTML中不更新,尽管在控制器中不断更新
- $scope变量发生更改时未触发Angular$watch
- 将Scope变量作为指针发送,并在控制器外部对其进行更改
- 正在从$scope变量中提取值
- 无法使用angularjs重置$scope变量
- 在 ng-click 中设置$scope变量指令
- 在从websocket服务器推送消息后更新$scope变量
- AngularJS中存在与$scope变量相关的问题.UI中的值未更改
- JavaScript未更新$scope变量的一部分
- 如何使用AngularJS在ng init中传递scope变量
- 如何访问ng-init或ng-checked中服务回调函数中声明的$scope变量
- 在我的HTML中用ng-init初始化$scope变量时出现问题
- angular js$scope变量与字符串绑定
- 如何在ng-init中使用$scope变量
- $scope变量从一个函数传递到另一个函数
- 如何在javascript中填充Angularjs$scope变量
- 阻止$scope变量副本侦听其原始副本
- 我们如何在Angular JS中使用$Scope变量而不声明