tombatossals / angular-leaflet-directive

AngularJS directive to embed an interact with maps managed by Leaflet library
http://tombatossals.github.io/angular-leaflet-directive
MIT License
1.5k stars 637 forks source link

How to have dynamic defaults? #1115

Open lf94 opened 8 years ago

lf94 commented 8 years ago

I have a leaflet directive I'm trying to re-use. When I set the property, I can't seem to change it.

Example:

Controller:

/* ...Controller boilerplate...*/
$scope.defaults = {};

$timeout(function() { $scope.defaults = { /* A bunch of leaflet configuration options...*/ }; });

Template:

<leaflet defaults="defaults"/>

Do I have to trigger some sort of reloading mechanism?

lungare commented 8 years ago

Not sure if one should use timeout but I think your problem is that the scope is not getting applied.

To do that add $scope.digest() like this $timeout(function() { $scope.defaults = { /* A bunch of leaflet configuration options...*/ }; $scope.digest() ; });

lf94 commented 8 years ago

The issue is angular-leaflet-directive does not watch for updates on the defaults argument.

My solution is to $destroy and then re-$compile the directive.

If anyone coming from Google results, let me know if you need a code example.