Hi Sanders,

Thanks for your reply. Your answer pointed me in the correct direction. Now 
I'm convinced, that I shouldn't be using private members inside templates 
and it's only a coincidence that it works.

My misunderstanding about using private members in the template was because 
I thought, that template might be evaluated INSIDE the scope of Component 
class. Now I checked the output of the Angular's compiler and can confirm 
that Component's members used in the template are accessed from OUTSIDE of 
the Component class' scope . Which makes your point about potential 
breakage of the code 100% valid.

It was very logical and appealing to use private for members relevant for 
component's templates only and public for members exposed as public API of 
the component... The truth is a bit disappointing.

Best,
Yaroslav.

On Wednesday, August 17, 2016 at 2:20:06 PM UTC+2, Sander Elias wrote:
>
> Hi Yarslav,
>
> In typescript a private is intended to be used within the class itself, 
> and any access from the outside should be prohibited. Technically, privates 
> should be inaccessible from the template. Due to the fact that it compiles 
> down to JS, and TS only does type-checking during dev and compile time, it 
> is possible to access privates from the template. However, with ES6 it is 
> possible to create true private instance variables. A future version of TS 
> might utilize this. When/If it does this, this option will render templates 
> that relay on private instance vars useless.
>
> While I like the sentiment that DrewMoore is expressing, strictly 
> speaking, using privates inside templates is not ok. They work because 
> there is a void between TS and the level of protection ES5 can deliver. 
>
> That's a TS issue more as it has anything to do with NG. 
>
> advice, don't use TS privates at all, as this is a confusing issue. If you 
> insist on privates, don't use them in the templates, but be aware that they 
> are in fact available (no so private at all!)
> if you really wan't privates, use some symbols, there are a couple of good 
> blogs around how to create real privates in ES6, and even in ES5 (although 
> that's much harder to do, and not 100%)
>
> Regards
> Sander
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to