Open nmccready opened 9 years ago
From @sibbl on July 18, 2015 8:29
Inject $window
into your function and then use $window.L
to access the leaflet namespace.
From @VolvoOlympian on July 18, 2015 9:2
Like this?
.controller('CourseDetailsCtrl', ['$scope', 'leafletData', function($scope, $window, leafletData) { leafletData.getMap('mymap').then(function(map) { $window.L.GeoIP.centerMapOnPosition(map, 15); }); } ])
But it does not work...sorry I am quite new to angular
From @sibbl on July 18, 2015 13:18
You need to add '$window'
to the list before your function as well:
.controller('CourseDetailsCtrl', ['$scope', '$window', 'leafletData', function($scope, $window, leafletData) { leafletData.getMap('mymap').then(function(map) { $window.L.GeoIP.centerMapOnPosition(map, 15); }); } ])
See the angular docs about dependency injection: https://docs.angularjs.org/guide/di
Is this resolved?
I don't know if we have the same issue, but i get the exact same error message. Please correct me if i'm wrong, but doesnt the error message say that the 'centerMapOnPosition' function can not be found on undefined, which means that L is correctly referenced, but that the GeoIP property is undefined, not the L property.
L contains a bunch of properties, but not the GeoIP one on which the centerMapOnPosition function should be accessible.
The code is taken directly from the sample in the github readme. Anyone know how to solve this error?
From @VolvoOlympian on July 18, 2015 8:16
I get "Cannot read property 'centerMapOnPosition' of undefined" with the following code on line
L.GeoIP.centerMapOnPosition(map, 15);
, am I missing something?.controller('CourseDetailsCtrl', ['$scope', 'leafletData', function($scope, leafletData) { leafletData.getMap('mymap').then(function(map) { L.GeoIP.centerMapOnPosition(map, 15); }); } ])
Copied from original issue: tombatossals/angular-leaflet-directive#856