2

I have decided to use AngularUI Map plugin to render Google Maps map within one of my views.

The template looks like this:

<div id="map">
<div ui-map="map" ui-options="mapOptions" id="map-canvas"
     ui-event="{'map-click': 'placeMarker($event, $params)'}">
</div>
</div>

The map is stored in the map scope variable of the controller. I've forced this behavior by explicitly creating this variable in the controller body: #scope.map = {};

What I would like is to externalize this map object to a service to avoid recreating it every time the view is accessed.

The service I wrote looks like this:

evee.factory('mapService', [function () {
    return {

    };
}]);

And the controller code looks like this:

var LocationController = function($scope, mapService) {

    $scope.map = mapService;

...

I can't make it work, the plugin always reinitializes the map. Should I drop the usage of the plugin and adopt a solution such as this non-plugin solution ?

Thank you.

Community
  • 1
  • 1
Radu Stoenescu
  • 3,187
  • 9
  • 28
  • 45
  • possible duplicate of [Reuse an AngularJS template between page views for the same route](http://stackoverflow.com/questions/16250652/reuse-an-angularjs-template-between-page-views-for-the-same-route) – Dan Dascalescu Oct 23 '14 at 08:32

1 Answers1

0

The angular-gm module reuses map instances so there is no memory leak.

Without the module, it seems like this is a non-trivial problem to solve with Angular.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404