2 years ago
#30714

AndrewBenjamin
Is there a way to hide 'Forced' public properties as if they were private?
A frustrating trend in Angular evolution is forcing properties to be public in order to use them in templates. For example, in [formControl]="myFormControl"
, myFormControl
must be public or errors are thrown.
I think this is bad. One reason is if I want to prevent someone from creating a race condition by setting myFormControl
directly, I either have to make it an accessor or I have to use tsdoc to beg future developers (namely myself) not to set it directly and to use the setMyFormControl()
instead.
Is making myFormControl
an accessor (set myFormControl() { *buncha logic to prevent race condition* }
) a bad idea that will gum up change detection?
Anyone know another solution? One where I can have a public property to bind to the formControl directive but that hides it to discourage setting it directly from outside the class?
Anyone else dislike Angular's decision to force these properties to be public? I've yet to find an explanation for it that convinces me it's not just strong-arming developers to conform to someone's opinion of the role of encapsulation in Angular.
angular
angular-directive
encapsulation
0 Answers
Your Answer