Доступ к слоту transclude в функции onInit

У меня есть старый компонент AngularJS < 1.4, который я хочу конвертировать с помощью angular.component('component', {bindings..., onInit...}), Предыдущий код выглядит так:

angular.module('Module').directive('myComponent', [
  () => {
    return {
      restrict: 'E',
      transclude: {
        slotA: '?slotA'
      },
      link(scope, _element, _attrs, _ctrl, transclude) {
        scope.isFilled = transclude.isSlotFilled('slotA');
      }
    };
  }
]);

что я хотел бы преобразовать во что-то вроде:

angular.module('Module').component('myComponent', {
  transclude: {
    slotA: '?slotA'
  },
  onInit() {
    this.isFilled = transclude.isSlotFilled('slotA');
  }
});

но как получить доступ к transclude переменная тогда?

1 ответ

Единственный способ, который я нашел, чтобы решить это:

angular.module('Module').component('myComponent', {
  transclude: {
    slotA: '?slotA'
  },
  controller: ['$transclude', ($transclude) => {
    this.$onInit = () => {
      this.isFilled = transclude.isSlotFilled('slotA');
    };
  }]
});
Другие вопросы по тегам