AngularJS Example

HTML

<div ng-app="app">
 <div ng-controller="ParentCtrl">
   <div class="assetsDirective"></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;
        self.toggleMarkers = function(value){
            console.log(1);
            self.showMarkers = angular.isDefined(value) ? !!value : !self.showMarkers;  
        };
    })


.directive("assetsDirective", function(){
    return {
        restrict: 'C',
        template: '<div><div data-ng-repeat="asset in assets" class="assetDirective" data-show-markers="markerService.showMarkers" data-asset="asset"></div></div>',
        controller: function($scope, markerService){
            $scope.assets = [{ name: "1" }, { name: "2" }];
            $scope.markerService = markerService;
        }
    }
})
.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;
}