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,当我向构造函数添加服务时出现错误:
我正在使用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 – Angular:如何在过滤器中使用$http
- 单元测试AngularJS指令,postLink D3不改变DOM
- 《数据结构》实验一: VC编程工具的灵活使用 第一部分
- angular 1.6 $http.get(...).success is not a function 解
- scala – 如何在lift项目中使用dispatch.json
- 默认情况下,如何配置GNU Emacs来编写UNIX或DOS格式的文件?
- 互联网 免费的WebService接口
- Unix内部的好书
- angularjs – 打印内容大于1页的Bootstrap Modal页面会导致
- bash – 如何匹配行/文本末尾的模式