NullInjectorError:AngularFirestore没有提供程序 [英] NullInjectorError: No provider for AngularFirestore

查看:54
本文介绍了NullInjectorError:AngularFirestore没有提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Angular,以寻求纠正错误的帮助: 我正在关注此链接: https://github. com/angular/angularfire2/blob/master/docs/install-and-setup.md 用angular2和angularfirestore2创建一个有角度的小型应用程序

I'm learning Angular looking for help in fixing the error: I'm following this link : https://github.com/angular/angularfire2/blob/master/docs/install-and-setup.md to create a angular small app with angular2 and angularfirestore2

但是当我点击ng服务时,我在浏览器控制台中收到以下错误.

but when I hit ng serve I am getting the below error in browser console..

StaticInjectorError[AngularFirestore]: 
  StaticInjectorError[AngularFirestore]: 
    NullInjectorError: No provider for AngularFirestore!
    at _NullInjector.get (core.js:923)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveToken (core.js:1211)
    at tryResolveToken (core.js:1153)
    at StaticInjector.get (core.js:1024)
    at resolveNgModuleDep (core.js:10585)
    at NgModuleRef_.get (core.js:11806)
    at resolveDep (core.js:12302)

我尝试使用Google搜索,但是没有找到确切的解决方案:(,

I tried googling it but didn't find the exact solution nothing worked for me :(,

这是我遵循的内容: 1)安装的节点版本8.9.1 2)npm install -g @ angular/cli-> 1.5.2版 3)ng新的项目名称" 4)npm安装angularfire2 firebase --save

Here is what I followed: 1) Installed Node Version 8.9.1 2) npm install -g @angular/cli --> Version 1.5.2 3) ng new 'project-name' 4) npm install angularfire2 firebase --save

这是我的app.module.ts文件:

Here are my app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AngularFireModule } from 'angularfire2';
import { environment } from '../environments/environment';

@NgModule({
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(environment.firebase)
  ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

app.component.ts:

app.component.ts:

import { Component } from '@angular/core';
import { AngularFirestore } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  constructor(db: AngularFirestore) {}
}

environemnt.ts:

environemnt.ts:

export const environment = {
  production: false,
  firebase: {
    apiKey: 'xxxxx',
    authDomain: 'aaaaaaa',
    databaseURL: 'bbbbbbbbbbbbbbbbbb',
    projectId: 'aaaaaaaaaaaaaa',
    storageBucket: 'aaaaaaaaaaaa',
    messagingSenderId: 'aaaaaaaaaaaaa'
  }
};

然后服务,我遇到了以上错误...

then ng serve, and I am getting the above error...

推荐答案

您应在 app.module.ts 中添加 providers: [AngularFirestore] .

You should add providers: [AngularFirestore] in app.module.ts.

@NgModule({
  imports: [
    BrowserModule,
    AngularFireModule.initializeApp(environment.firebase)
  ],
  declarations: [ AppComponent ],
  providers: [AngularFirestore],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

这篇关于NullInjectorError:AngularFirestore没有提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆