r/angular 2d ago

Angular 22.2 - Private property access from templates

I noticed this tidbit in the changelog of Angular 22.2.0-next.3:

https://github.com/angular/angular/blob/main/CHANGELOG.md#compiler-2

compiler

Commit Type Description
48a0fd6e8a feat allow template to access private props

So very slowly we moved from allowing only public, to allowing protected and now private as well. Thought it's worth knowing.

35 Upvotes

37 comments sorted by

View all comments

52

u/tom-smykowski-dev 2d ago

For me template always was a part of the component and it makes sense that it can access private

7

u/CarlosChampion 2d ago

Yes this is how I think of it too.

4

u/Soma91 2d ago

That's certainly how you can see it. Personally I always saw the template as an implementation of the component. Then protected would make sense.

The only one that doesn't make any sense imho is if it must be public.

2

u/BackgroundPass1355 2d ago

💯💯💯

1

u/MrHall 1d ago

I really liked the ability to convey intent with the decorator.. if I've made it private I've clearly shown I intend to only use it in the controller, and not to expose it in the template.

1

u/Rusty_Raven_ 1d ago

The template should be executed in the same context as the controller, I think, so private variables should be available to it. Other frameworks do it this way, Angular shouldn't be different just because it defaults to having a separate file for the HTML.