2

All the functions that I am making in a component are accessible to the view even the private functions.

HTML

 <p (click)="accessable(name)">{{name}}</p>
 <p (click)="shouldNotBeAccessable(name)">{{name}}</p>

Component

accessable(item): void{
        this.selected = item;
}
private shouldNotBeAccessable(item):void{
        this.selected = item;
}

Problem

I don't want the shouldNotBeAccessable to be accessible from the view.

Request

Is it possible to stop the function to stop being used from view? If yes then how?

Vikas Bansal
  • 10,662
  • 14
  • 58
  • 100
  • 6
    Private methods will fail when you build with AoT. Otherwise I don't think there is a way, because privacy won't be enforced at runtime because JavaScript doesn't know about that concept. – Günter Zöchbauer Mar 24 '17 at 12:26
  • Nothing private in JavaScript. Typescript is superset. You can emulate though. http://stackoverflow.com/questions/16919473/private-functions-in-typescript – Amit Mar 24 '17 at 12:34
  • I am totally agree... However I am trying to find out that is it possible to reveal only the relevant variables and functions to the UI? and what about `closures`, cannot we achieve the encapsulation using them? – Vikas Bansal Mar 24 '17 at 12:38

0 Answers0