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

351
Views
Angular service with providedIn: 'root' is an empty object

I just created a brand new service inside an angular application and use providedIn: 'root' to make it available anywhere in the application.

But when I import it and try to use it says its methods are undefined.

Here is the code

service.ts

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class Service {
  public publicMethod() {}
}

component.ts

import { Service } from 'path/to/service';
import { Component } from '@angular/core';
import { AccountService } from 'app/core';
@Component({
    selector: 'footer',
    templateUrl: './footer.component.html',
})
export class FooterComponent {
  constructor(private readonly service: Service) {
     this.service.publicMethod // undefined
  }
}

Other services imported the same way are working fine. What can cause this issue?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try to add your service you want to inject in providers : [ ] in your core.module and in your AccountService replace @Injectable({ providedIn: 'root' }) with @Injectable()

about 4 years ago · Juan Pablo Isaza Report

0

@ChrisHamilton you are right, an imported module to that service caused the issue, it was not provided anywhere. Added providedIn: root to there was solved the issue.

about 4 years ago · Juan Pablo Isaza 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!