Answer the question
In order to leave comments, you need to log in
Why doesn't the data in the parent directive change?
<div data-block>
<div data-block-header>
</div>
<div data-block-body>
</div>
</div>
angular.module('app').directive('block', [function() {
return {
restrict: 'A',
controller: function($scope, $element) {
$scope.showBody = false;
this.toggleBody = function() {
$scope.showBody = !$scope.showBody;
}
$scope.$watch('showBody', function() {
console.log('changed')
})
},
link: function(scope, element, attrs, ctrl) {}
}
}]);
angular.module('app').directive('blockHeader', [function() {
return {
restrict: 'A',
require: '^block',
template: '<div>header</div>',
controller: function($scope, $element) {},
link: function(scope, element, attrs, ctrl) {
element.bind('click', function() {
ctrl.toggleBody();
})
}
}
}]);
angular.module('app').directive('blockBody', ['$http', '$templateRequest', '$compile', function($http, $templateRequest, $compile) {
return {
restrict: 'A',
require:'^block',
template: '<div ng-show="showBody">Body</div>',
controller: function($scope, $element) {
},
link: function(scope,element,attrs,ctrl){
}
}
}]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question