问题描述
我正在学习 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.mdto create a angular small app with angular2 and angularfirestore2
但是当我点击 ng serve 时,我在浏览器控制台中收到以下错误..
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)
我尝试使用谷歌搜索但没有找到确切的解决方案对我没有任何作用:(,
I tried googling it but didn't find the exact solution nothing worked for me :(,
这是我遵循的:1) 已安装节点版本 8.9.12) npm install -g @angular/cli --> 1.5.2 版3) ng 新的项目名称"4) npm install angularfire2 firebase --save
Here is what I followed:1) Installed Node Version 8.9.12) npm install -g @angular/cli --> Version 1.5.23) 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) {}
}
环境.ts:
export const environment = {
production: false,
firebase: {
apiKey: 'xxxxx',
authDomain: 'aaaaaaa',
databaseURL: 'bbbbbbbbbbbbbbbbbb',
projectId: 'aaaaaaaaaaaaaa',
storageBucket: 'aaaaaaaaaaaa',
messagingSenderId: 'aaaaaaaaaaaaa'
}
};
然后 ng serve,我收到了上述错误...
then ng serve, and I am getting the above error...
推荐答案
您应该在 app.module 中添加
.providers: [AngularFirestore]
.ts
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 没有提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!