Custom Directives In Angularjs
In a navbar whenever we click on a country name the respective map should appear on the screen . As of now , the country coordinates are hard coded into the directive I built. But
Solution 1:
You directive tag will look something like below, which expect selected country.
<divng-if="selectedCountry"><country-tab-barcountry="selectedCountry"></country-tab-bar><div>
then have itemClicked
inside a controller which will have selectedCountry
scope.itemClicked = function(value){
$scope.selectedCountry = value;
}
Directive
app.directive('countryTabBar',function(){
return {
restrict: ';E',
templateUrl: 'countryDirective.tpl.html',
scope : {
country: '='
}
}
});
countryDirective.tpl.html
<div><div>{{country.label}}</div><imgng-src="https://maps.googleapis.com/maps/api/staticmap?center={{country.coords}}&zoom=4&size=800x200"></div>
Post a Comment for "Custom Directives In Angularjs"