Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

340
Views
How to use UpgradeComponent to a AngularJS directive that uses $attrs in Angular

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!