1

Currently I have this .directive in AngularJS:

aegroApp.directive('poorLegacy', function () {
  return {
    restrict: 'E',
    scope: {
      hasSomething: '=?',
      anotherBinding: '@',
    },
    controller,
    templateUrl: function (_, attrs) {
      return attrs.hasSomething ? 'file.html' : 'file2.html';
    },
  }
});

function controller($attrs, /* others */) {
  // perform some checks with $attrs
  // rest of the code
}

and I'm trying to use UpgradeComponent to be able to use this in Angular:

@Directive({ selector: 'my-bridge' })
export class MyBridgeDirective extends UpgradeComponent {
  @Input() hasSomething?: boolean;
  @Input() anotherBinding?: string;

  constructor(elementRef: ElementRef, injector: Injector) {
    super('poorLegacy', elementRef, injector);
  }
}
<my-bridge [hasSomething]="false"></my-bridge>

But it fails... and the reason is explained here (basically it doesn't support $attrs).

So, the question is: how could I use that legacy directive without rewriting this right now?

dev_054
  • 3,448
  • 8
  • 29
  • 56

0 Answers0