AngularJS Example
HTML
<div ng-app="app">
<div ng-controller="ParentCtrl">
<div class="assetsDirective" data-show-markers="markerService.showMarkers"></div>
<div class="toolBarDirective" data-show-markers="markerService.showMarkers"></div>
</div>
</div>
CSS
</style>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.css"/>
<style>
JavaScript
angular.module('app', [])
.service("markerService", function(){
var self = this;
self.showMarkers = false;
})
.directive("assetsDirective", function(){
return {
restrict: 'C',
scope: {
showMarkers: "=showMarkers"
},
template: '<div><div data-ng-repeat="asset in assets" class="assetDirective" data-show-markers="showMarkers" data-asset="asset"></div></div>',
controller: function($scope){
$scope.assets = [{ name: "1" }, { name: "2" }];
}
}
})
.directive("assetDirective", function(){
return {
restrict: 'C',
scope: {
asset: "=asset",
showMarkers: "=showMarkers"
},
replace: true,
template: '<div>{{ showMarkers ? "Show" : "Hidden" }} Name: {{ asset.name }}</div>'
}
})
.directive("toolBarDirective", function(){
return {
restrict: 'C',
scope: {
showMarkers: "=showMarkers"
},
template: '<div><button data-ng-click="toggleMarkers()">Toggle Markers</button></div>',
controller: function($scope){
$scope.toggleMarkers = function(){
$scope.showMarkers = !$scope.showMarkers;
}
}
}
});
function ParentCtrl($scope, markerService){
$scope.markerService = markerService;
}