I am trying to access a variable defined in the controller that I created so that I can scroll through the list and place markers using google maps api. I tried a bunch of things, but I'm stuck. This is the controller:
app.controller('MainController', ['$scope', 'meteorite', function($scope, meteorite) {
meteorite.success(function(data) {
$scope.meteorites = data;});
}]);
And this is the part where I am trying to access the variable.
<div id="map">
</div>
<div class="main" ng-controller="MainController">
<div id="stuff" ng-repeat="meteorite in meteorites">
<h1>{{meteorite.name}} : {{meteorite.mass | number}}</h1>
</div>
</div>
<script>
var map;
var myLatLng = {lat: -25.363, lng: 131.044};
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
zoom: 10
});
for (var i = 0; i < [This is where i want to access meteorites]; i++) {
var marker = new google.maps.Marker({
position: {meteorites[i].lat, meteorites[i].long},
map: map
});
}
}
</script>
EDIT
The answer I got worked fine after adding one thing (ng-if = "meteorites"):
<g-map ng-if="meteorites" meteorites="meteorites"></g-map>
source
share