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

276
Views
Angular 5, NullInjectorError: No hay proveedor para el servicio

Hola, estoy tratando de implementar Firestore en mi aplicación web, cuando agrego el servicio al constructor, aparece el error:

NullInjectorError: ¡No hay proveedor para TesteventService!

Estoy usando Angular 5, angularfire2/firestore y mecanografiado 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() } }

componente.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){})

Cuando agrego eventos de TesteventSerivice, aparece el error, mientras que no se ejecuta nada.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Debe agregar TesteventService en proveedores en importaciones en su app.module.ts

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

0

Anote su clase de servicio con -

 @Injectable({ providedIn: 'root' })

El servicio en sí es una clase que generó la CLI y está decorada con @Injectable() . De forma predeterminada, este decorador tiene una propiedad providedIn , que crea un proveedor para el servicio. En este caso, providedIn: 'root' especifica que Angular debe proporcionar el servicio en el inyector raíz.

over 4 years ago · Santiago Trujillo Report

0

Hay dos posibilidades para solucionar este problema:

  1. Puede proporcionar el nombre de su servicio en la matriz de proveedores de app.module.ts de esta manera y el error desaparecerá:
 imports: [ ], declarations: [ ], providers: [ TesteventService ]
  1. Para algunas de las últimas versiones de angular, simplemente puede anotar el servicio deseado de esta manera:
 @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!