Edit: this answer is now incorrect. There were no official instructions on this topic when I published them, but as @Yaroslov explained (excellent and correct) the answer is no longer the case: Codelizer now warns and AoT will not compile when referencing private variables in component templates . However, at the conceptual level, everything here remains valid, so I will leave this answer as it seems useful.
Yes, it is expected.
Keep in mind that private and other access modifiers are Typescript constructs, while Component / controller / template are angular constructs that Typescript knows nothing about. Access modifiers control visibility between classes: creating a private field prevents other classes from accessing it, but templates and controllers are things that exist inside classes.
This is not technically true, but (instead of understanding how classes relate to decorators and their metadata), it may be useful to think about it this way because the important thing (IMHO) is to move from thinking about the template and as separate entities, considering them as single parts of the Component is one of the main aspects of the ng2 mental model.
Thinking about it this way, obviously, we expect that the variables of the private class in the component class will be visible in its template, for the same reason we expect that they will be visible in the private methods of this class.
drew moore Jan 03 '15 at 8:37 2016-01-03 08:37
source share