Detect if a transclude content has been given for a angularjs directive

After release of Angular v1.5 with multi-slot transclusion it’s even simpler. For example you have used component instead of directive and don’t have access to link or compile functions. Yet you have access to $transclude service. So you can check presence of content with ‘official’ method:

app.component('myTransclude', {
  transclude: {
    'slot': '?transcludeSlot'
  },
  controller: function ($transclude) {
    this.transcludePresent = function() {
      return $transclude.isSlotFilled('slot');
    };
  }
})

with template like this:

<div class="progress" ng-class="{'with-label': withLabel}">
    <div class="label"><span ng-transclude="slot"></span>
    <div class="other">...</div>
</div>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)