Last active
April 18, 2023 07:30
-
-
Save TweededBadger/383f73171d29da6b5964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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