Skip to content

Instantly share code, notes, and snippets.

@TweededBadger
Last active April 18, 2023 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TweededBadger/383f73171d29da6b5964 to your computer and use it in GitHub Desktop.
Save TweededBadger/383f73171d29da6b5964 to your computer and use it in GitHub Desktop.
angular.module('SvgMapApp').directive('svgMap', ['$compile', function ($compile) {
return {
restrict: 'A',
templateUrl: 'img/Blank_US_Map.svg',
link: function (scope, element, attrs) {
var regions = element[0].querySelectorAll('.state');
angular.forEach(regions, function (path, key) {
var regionElement = angular.element(path);
regionElement.attr("region", "");
regionElement.attr("dummy-data", "dummyData");
$compile(regionElement)(scope);
})
}
}
}]);
angular.module('SvgMapApp').directive('region', ['$compile', function ($compile) {
return {
restrict: 'A',
scope: {
dummyData: "="
},
link: function (scope, element, attrs) {
scope.elementId = element.attr("id");
scope.regionClick = function () {
alert(scope.dummyData[scope.elementId].value);
};
element.attr("ng-click", "regionClick()");
element.removeAttr("region");
$compile(element)(scope);
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment