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

273
Views
Angular 5, NullInjectorError: No provider for Service

Hello im trying to implement firestore into my web application, when i add the service to contructor the error:

NullInjectorError: No provider for TesteventService!

I'm using Angular 5, angularfire2/firestore and typescript 2.7.1

testevent.service.ts

import { Injectable } from '@angular/core';
import { AngularFirestore } from 'angularfire2/firestore'

@Injectable()
export class TesteventService {

  constructor(private afs: AngularFirestore) { }

  addEvent(eventData){
    this.afs.collection('testevent').add(eventData).then(() => {
      console.log('Done');
    })
  }

  getEvent(){
    return this.afs.collection('testevent', ref => ref.orderBy('id')).valueChanges()
  }
}

component.ts

import { Component, OnInit } from '@angular/core';
import { TesteventService } from '../../providers/testevent.service';
import { AngularFirestore } from 'angularfire2/firestore';

export class CsvImportComponent implements OnInit {
  data_rows = []

  constructor(private event: TesteventService){})

When I add events from TesteventSerivice i get the error, while nothing is run.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You need to add TesteventService under providers under imports in your app.module.ts

providers: [
  TesteventService 
]
over 4 years ago · Santiago Trujillo Report

0

Annotate your service class with -

@Injectable({ providedIn: 'root' })

The service itself is a class that the CLI generated and that's decorated with @Injectable(). By default, this decorator has a providedIn property, which creates a provider for the service. In this case, providedIn: 'root' specifies that Angular should provide the service in the root injector.

over 4 years ago · Santiago Trujillo Report

0

There are two possibilities to solve this problem:

  1. You can provide your service name in app.module.ts providers array like this way and error will be gone:
imports: [
],

declarations: [
],

providers: [  TesteventService ]
  1. For some of the latest versions of angular you can simply annotate you desired service this way:
@Injectable({ providedIn: 'root' })
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!