0

I have code like this :

$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])];

How to simplify in AngularJS style to take more iteration?

2 Answers 2

2

$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]));
}

Sign up to request clarification or add additional context in comments.

1 Comment

Cool, as expectations. Thanks @CodeiSir
0

Just to clarify the CodeiSir answer. Is not "Angular" iteration what he showed is javascript. You can use it for read data too, as you use the angular ng-repeat in the html.

more info here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.