Home » Javascript » Angular 6: Strange “Property xxx is protected and only accessible within class and its subclasses

Angular 6: Strange “Property xxx is protected and only accessible within class and its subclasses

Posted by: admin August 19, 2018 Leave a comment

Questions:

I have a library project that I’m migrating to Angular 6 and Angular CLI 6.

There’s an abstract class called NativeFormElementChild that has some private properties: _id, _required, _ariaDescribedBy, and _ariaRequired.

Then I have a directive, InputDirective, that’s applied to a <input> as an attribute (adds some extra functionality). InputDirective extends from NativeFormElementChild.

Now when I try to build this in Angular 6, I get errors galore. Everywhere I use my InputDirective, I get four errors:

  • Property ‘_id’ is protected and only accessible within class ‘NativeFormElementChild’ and its subclasses.
  • Property ‘_required’ is protected and only accessible within class ‘NativeFormElementChild’ and its subclasses.
  • Property ‘_ariaDescribedBy’ is protected and only accessible within class ‘NativeFormElementChild’ and its subclasses.
  • Property ‘_ariaRequired’ is protected and only accessible within class ‘NativeFormElementChild’ and its subclasses.

I’m not trying to access these properties from anywhere except inside NativeFormElementChild. So I have no idea where these errors are coming from. Using Angular 5, I don’t get any of these errors.

Answers: