I have written a custom directive in AngularJS. And I have to use isSlotFilled method of $transclude. The JavaScript of the directive:
define(['../directives-module'], function (directivesModule, $scope, $transclude) {
directivesModule.directive('news', function() {
return {
restrict: 'E',
replace: true,
transclude: {
'heading': 'heading',
'content': '?content'
},
scope: {
'cmsContent': '@'
},
templateUrl: 'directives/news.html',
link: function(scope, element, attrs, ctrl, transclude){
console.log($transclude.isSlotFilled(content));
},
};
});
});
I have tried to output a console.log() to check the method works. The console.log() above does not work, saying:
TypeError: Cannot read property 'isSlotFilled' of undefined
Actually, I have to use this method on the HTML file of the directive. The file news.html contains:
<div class="row">
<div class="largeText shadow1" ng-transclude="heading"></div>
<div class="mediumText shadow2" ng-transclude="content"
ng-class="{'hide' : $transclude.isSlotFilled(content)}">
</div>
</div>
As you see in the ng-class, it will hide the div if the content slot is not filled. However the condition here inside ng-class always returns false. I'm sure I am missing something at injecting $transclude. What should I do to properly use this method from the news.html?