Perhaps the question is not phrased properly, but here is the idea I am working on.
I have a navbar
set up with an array of countries that includes their names and coordinates.
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Welcome to the world of directives!</a>
</div>
<ul class="nav navbar-nav">
<li ng-repeat="countryTab in countries" ng-click="itemClicked(countryTab.label)" style="cursor:pointer">
<a>{{countryTab.label}}</a>
<country-tab-bar country="selectedCountry"></country-tab-bar>
</li>
</ul>
</div>
</nav>
<script>
var app = angular.module('app',[]);
app.controller('appCtrl',function($scope){
$scope.countries = [{
id: 1,
label: 'Italy',
coords: '41.29246,12.5736108'
}, {
id: 2,
label: 'Japan',
coords: '37.4900318,136.4664008'
}, {
id: 3,
label: 'USA',
coords: '37.6,-95.665'
}, {
id: 4,
label: 'India',
coords: '20.5937,78.9629'
}];
});
</script>
Now the country-tab-bar
directive contains the template showing the name and map using the coordinates given in the array.
I attempted
app.directive('countryTabBar',function(){
return {
restrict: 'E',
scope:{
country: '='
},
template: '<div>'+
' <div>Italy</div>'+
' <br/>'+
' <img ng-src="https://maps.googleapis.com/maps/api/staticmap?center={{country.coords}}&zoom=4&size=800x200"> '+
'</div>',
link : function(scope,elem,attrs){
scope.itemClicked = function(value){
scope.selectedCountry = value;
}
}
}
});
However, nothing happens when clicking on the country names.
The current UI layout is skewed.
https://i.sstatic.net/ewB5A.png
How can this be fixed? Suggestions are welcome. The map should only display after clicking a name, not before.