Private naming convention in the official Angular 2 http tutorial

I am trying to understand how a private variable is called in the official Angular 2 http tutorial

In the section above, there is a file called app/toh/hero.service.ts , which (basically):

 @Injectable() export class HeroService { constructor (private http: Http) {} private _heroesUrl = 'app/heroes'; getHeroes () { return this.http.get(this._heroesUrl) .map(res => <Hero[]> res.json().data) .catch(this.handleError); } private handleError (error: Response) { // in a real world app, we may send the server to some remote logging infrastructure // instead of just logging it to the console console.error(error); return Observable.throw(error.json().error || 'Server error'); } } 

There is a personal variable _heroesUrl . So, there is a convention for running private variables and underlined methods.

But why is the underscore not used for private http and private handleError ? Is it just a typo or is it a reason for this?

+5
source share
1 answer

This is just a typo. For TS, this does not apply, it is just an agreement. Inside the Angular2 codebase, this is used sequentially to allow translation to Dart, where _ is not only a convention, but a replacement for the private keyword (which is not in Dart)

+2
source

Source: https://habr.com/ru/post/1242489/


All Articles