I am trying to write a directive to create a map component so that I can write something like:
<map></map>
Now the directive looks like this:
angular.module('myApp') .directive('map', function (GoogleMaps) { return { restrict: 'E', link: function(scope, element, attrs) { scope.$watch('selectedCenter', function() { renderMap(scope.selectedCenter.location.latitude, scope.selectedCenter.location.longitude, attrs.zoom?parseInt(attrs.zoom):17); }); function renderMap(latitude, longitude, zoom){ GoogleMaps.setCenter(latitude, longitude); GoogleMaps.setZoom(zoom); GoogleMaps.render(element[0]); } } }; });
The problem is that the "look" inside the directive does not look very good, thinking about the possibility of reusing the component. So I think the best thing is to do something like:
<map ng-model="selectedCenter.location"></map>
But I donβt know if this is good using angular directives inside user directives or how I can get the object specified in the ng-model attribute in the link function with a custom directive.
source share