作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
你好,我正在尝试将 firestore 实现到我的 Web 应用程序中,当我将服务添加到构造函数时出现错误:
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()
}
}
组件.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 的 imports 下的 providers 下添加 TesteventService
providers: [
TesteventService
]
关于 Angular 5,NullInjectorError : No provider for Service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49112005/
我是一名优秀的程序员,十分优秀!