Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: Why to use private access specifier to instantiate the providers in constructor

Why to use private access specifier only to instantiate the providers in constructor ? Is there any specific reason to use private access specifiers only ?

Private injection

constructor(private service: InjectedService)

Public injection

constructor(service: InjectedService)
like image 562
Rajni Avatar asked Dec 10 '22 15:12

Rajni


1 Answers

Using private acts a shorthand, instead of doing:

constructor(service: InjectedService) {
   this.service = service
}

you can:

constructor(private service: InjectedService) {}
like image 67
Arun Ghosh Avatar answered Dec 13 '22 23:12

Arun Ghosh