When do we need to use @Injectable for our services in Angular2?

All:

Im pretty new to Angular2, when I get into the dependency injection section, this notation @Injectable()makes me confused. Just want to make sure my understanding of @Injectable () is true:

  • @Injectable() indicates that the class follows; it can be entered as a service.
  • @Injectable()indicates that the class follows another service @Injectable()entered at.

Is that pretty much what it means @Injectable()? Anything else you need to pay special attention to this designation?

And we cannot decide which case will happen (or both will) until we look at the definition of a class, is this right?

thank

+3
source share
1

, @Injectable , :

, , Injector .... Injector NoAnnotationError , @Injectable.

, Plunker. , (1) .

@Injectable , Angular , . , . , , Angular .

( ).

@Injectable()?

@Injectable() , . , , @Injectable().

, @Injectable() HeroService, . , . , Angular , Logger.

, , . @Injectable, - .

, @Injectable , , , @Injectable, .

@Injectable() , , , , , . :

  • : @Injectable(), .
  • : , , .

, (2) .

+4

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


All Articles