Angular 5,NullInjectorError:没有服务提供者

前端之家收集整理的这篇文章主要介绍了Angular 5,NullInjectorError:没有服务提供者前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
您好我试图在我的Web应用程序中实现firestore,当我向构造函数添加服务时出现错误

NullInjectorError: No provider for TesteventService!

我正在使用Angular 5,angularfire2 / firestore和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){})

当我从TesteventSerivice添加事件时,我得到错误,而没有任何运行.

解决方法

您需要在app.module.ts中的导入下的提供程序下添加TesteventService

providers: [
  TesteventService 
]

猜你在找的Angularjs相关文章