I have created many variables and accessing it in respective template/html. By default, all variables will be public. and these public variables is problematic, so i want to convert them to private. but, as soon as I am converting these private variables to public, I am getting error of private members cannot be used outside the class. conceptually, it is absolutely correct. But, in component, template/html and *.ts files belongs to same thing, correct me if i am wrong. then, why can't I use private variables created in ts file to corresponding template/html?
if both ts file and html/template file are separate then, how can i access private variable in html?
I am using typescript.
- converted public variables to private in ts file
- use private variables in html of same component
test.component.ts
public myVar = 'iCreatedThisVariable';
to
private myVar = 'iCreatedThisVariable';
test.component.html
<p>{{myVar}}</p>
I should be able to use private variables in html, if both ts file and html belong to the same class.
If they are different, then how can I use private variables in html using angular2+?