Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

186
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?

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.