Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 429
Mr. Toast Avatar asked Mar 05 '18 13:03

Mr. Toast


1 Answers

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

providers: [   TesteventService  ] 
like image 69
Sajeetharan Avatar answered Sep 28 '22 09:09

Sajeetharan