Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

275
Vistas
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 Respuestas
Responde la pregunta

0

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

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

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda