简体   繁体   中英

angular interface style guide - unclear recommendations

I've read the Angular style guide for interfaces , and there are two recommendations there that are completely unclear to me:

Consider using a class instead of an interface for services and declarables (components, directives, and pipes).

Consider using an interface for data models.

Why? A class can act as an interface (use implements instead of extends).

Why? An interface-class can be a provider lookup token in Angular dependency injection.

In the first case, is there even an alternative to defining a service as a class?

In the second case, the recommendation seems contrary to Angular's Tour of Heroes tutorial (has it been updated lately?), where the Hero model is defined as a class, like so:

export class Hero {
  constructor(public id: number, public name: string) { }
}

And also, what is an interface-class and what does it mean a provider lookup token ?

I think that several examples could really clarify things here.

Thanks.

  1. This is a little out of context but what they are referring to is using a class (model) for retrieving data ie this.service.getSomething().subscribe((model: myModel) => model); .

  2. An interface-class is a class that acts as an interface aka a model.

  3. A provider lookup token is how angular knows what provider to use. There is a more in-depth explanation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM