Sorry for duplicating the question. But I found something useful and updated with it.
This is my directive :
App.directive('mapUsa', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.vectorMap({
map: 'us_aea_en',
backgroundColor: 'transparent',
zoomButtons: false,
regionStyle: {
initial: {
fill: '#343434'
},
hover: {
fill: '#242424'
}
},
markerStyle: {
initial: {
fill: '#F0A518',
stroke: '#F0A518',
}
},
onRegionClick: function(event, code) {
},
markers: [
{latLng: [37.78, -122.41], name: 'San Francisco', style: {r: 10}},
{latLng: [40.71, -74], name: 'New York City', style: {r: 15}},
{latLng: [41.89, -87.62], name: 'Chicago', style: {r: 5}},
{latLng: [34.00, -118.25], name: 'Los Angeles', style: {r: 20}},
{latLng: [34.00, -106.00], name: 'New Mexico', style: {r: 10}},
{latLng: [44.50, -100.00], name: 'South Dakota', style: {r: 13}},
{latLng: [25.78, -80.22], name: 'Miami', style: {r: 7}},
]
});
},
controller: ['$scope', 'citiesData', function($scope, citiesData) {
citiesData.getCitiesData()
.then(function(data) {
$scope.cities = data;
}, function(errorStatus) {
$scope.errorStatus = errorStatus;
})
}]
}
}])
In my controller I'm loading a json file and I can of course access it with my HTML using the angular expression.
But now on the onRegionClick
I get the code of the cities whenever I click on a region.
And this is how JSON looks like.
{ "US-AL": { "name": "Alabama", "population": 4833722 }, "US-AK": { "name": "Alaska", "population": 735132 }
I have created JSON objects with code I get from the onRegionClick
.
I wanted to print out the population count from the city code I get on onRegionClick
and passing to it the controller and then finally using that code to get the data from JSON.
Please do help me out in this. As I didn't seriously couldn't understand on how to pass a param value from directive to a controller.
In my HTML I used expression like this from the variable created in the controller.
{{ cities.AL.name }}
It is ofc working fine. But I wanted to replace the AL
with the code I get from the onRegionClick
.
Thanks in advance.