I'm trying to add a google map in angular JS... and have been struggling. I didn't want to use one of the angular dependencies, but simulate the 'async defer' on the Google JS API site.
I'm pretty new to Angularjs but get the concept of keeping things assigned to the controllers scope. Pretty sure it's just something dumb, but not sure what... any help would be awesome :-)
(function () {
'use strict';
app.controller('travelCtrl', ['$scope', function($scope) {
$scope.injectScript = function(element) {
var scriptTag = angular.element(document.createElement('script'));
scriptTag.attr('charset', 'utf-8');
scriptTag.attr('src', 'https://maps.googleapis.com/maps/api/js?key=MYKEY');
element.append(scriptTag);
return {
link: function(scope, element) {
injectScript(element)}}};
$scope.initMap = function() {
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('kc-map'), {
zoom: 4,
center: uluru
});
};
}]);
})();
HTML
<div ng-controller="travelCtrl" id="kc-map"></div>
angular.element(element).append(scriptTag);MKEY seems to be invalid api key tho