First of all, if you want the Google Maps API to work with AngularJS , you have two solutions:
, .
AngularJS, API. AngularJS, .
Index.html:
<html ng-app="myApp">
<head>
<title>AngularJS-Google-Maps</title>
<link rel="stylesheet" href="style.css">
<script src="../lib/angular.min.js"></script>
<script src="app.js"></script>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=
YourKey&sensor=false">
</script>
</head>
<body>
<my-maps id="map-canvas"></my-maps>
</body>
</html>
app.js:
var myApp = angular.module("myApp",[]);
myApp.directive("myMaps", function(){
return{
restrict:'E',
template:'<div></div>',
replace:true,
link: function(scope, element, attributes){
var myLatLng = new google.maps.LatLng(YourLat,YourLong);
var mapOptions = {
center: myLatLng,
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(attributes.id),
mapOptions);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"My town"
});
marker.setMap(map);
}
};
});
style.css
height: 400px;
width: 700px;
border: 2px solid red;
}
, , AngularJS.
Plunk .
API Google -, StackOverflow.
, , .., :
JSFiddle, @Shreerang Patwardhan Polylines ( ).
, myMaps.js Inject App Module. DRY (Do not Repeat Yourself) , , Angular Google Maps. , , Google Maps.
- :
myApp.directive("myMap", function(){ . . . });
var myApp = angular.module("myApp",['myMaps']);
, .