加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 18:01:42 所属栏目:安全 来源:网络整理
导读:您好我试图在我的Web应用程序中实现firestore,当我向构造函数添加服务时出现错误: NullInjectorError: No provider for TesteventService! 我正在使用Angular 5,angularfire2 / firestore和typescript 2.7.1 testevent.service.ts import { Injectable } fr
您好我试图在我的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 
]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读