Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
Why are components not marked with @injectable annotation, but services need to be?

While defining a service / service class in angular, class is decorated with @injectable() decorator.

As per angular guidebook: @Injectable() marks a class as available to an injector for instantiation.

Then why it is not needed while creating a component?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

From the Angular documentation (emphasis mine):

Injectors are also responsible for instantiating components like HeroesComponent. So why doesn't HeroesComponent have @Injectable()?

You can add it if you really want to. It isn't necessary because the HeroesComponent is already marked with @Component, and this decorator class (like @Directive and @Pipe, which you learn about later) is a subtype of @Injectable(). It is in fact @Injectable() decorators that identify a class as a target for instantiation by an injector.

In other words, by marking a class as being a component, directive or pipe, you're implicitly marking them as injectable as well.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!