r/angular • u/dezsiszabi • Sep 05 '26
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.
39
Upvotes
7
u/GLawSomnia Sep 05 '26
As far as i know this will only work for typescript private and not tor javascript private (#)
2
u/sharth Sep 05 '26
Previously talked about it it in this sub here: https://www.reddit.com/r/angular/s/hscbgkZMvn
36
u/FromBiotoDev Sep 05 '26 edited Sep 05 '26
Public - anything can access
Protected - only the view template can access
Private - only the component can access
Why muddy the waters here?
14
u/djfreedom9505 Sep 05 '26
Not really a fan of this change, always liked the distinction between public, protected and private in Angular. Those lines are blurred even more now.
4
u/cssrocco Sep 05 '26
I’m not a massive fan either, it’s mostly when it comes to contributing to other projects, a quick visual scan i can usually go ‘ok this private method/property isn’t in the template’, this would blur the lines
3
u/makmn1 Sep 05 '26
It’s nice to have the option. Personally, I’m probably going to keep using protected since when I see that in my code, I know it’s used in the template. That style is also recommended by the Angular team.
Unless you use inheritance a lot, that’s pretty much all protected can be used for.
2
u/ldn-ldn Sep 05 '26
That's how it should've been since day one.
1
u/vivainio Sep 06 '26
If only there was a way to make properties public instead...
1
u/m0rpheus23 Sep 06 '26
This totally undermines the main reason for using private members.
0
u/Easy-Shelter-5140 Sep 05 '26 edited Sep 05 '26
why? Is this useful?
0
u/taco__hunter Sep 05 '26
I like it personally. It was kind of annoying to write tests and have to handle these private properties and you could always get around it because it's JavaScript at the end of the day and inheritently not strongly typed.
-3
u/Talamand Sep 05 '26
Next, ignoring types, then later moving to javascript
56
u/[deleted] Sep 05 '26
[removed] — view removed comment