Tutaj masz dwa sposoby. Z gory w dol oraz z dolu w gore.
// z gory w dol
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<button ng-click="toggle()">
Click
</button>
<div some-directive show="show"> </div>
</div>
</div>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope){
$scope.show = false;
$scope.toggle = function(){
$scope.show = !$scope.show;
console.log($scope.show);
}
}
angular.module("myApp").directive("someDirective",function(){
return {
restrict: 'EA',
scope:{
show:"="
},
template:"<h1 ng-show='show'>Hello</h1>",
link: function(scope, element, attrs, controller) {
}
}
});
// z dolu w gore
<div ng-app="myApp">
<div ng-controller="AppCtrl">
<h1 ng-show="show">
Show Text
</h1>
<div some-directive show="showDiv(bool)"></div>
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.controller("AppCtrl", function ($scope) {
$scope.show = false;
$scope.showDiv = function (bool) {
$scope.show = bool;
};
});
myApp.directive("someDirective", function () {
return {
restrict:'EA',
scope: {
show: "&"
},
template: '<button ng-click="show({bool:true})">Click me</button>',
};
});