我正在学习Angular寻找修复错误的帮助:
我正在关注此链接: https://github.com/angular/angularfire2/blob/master/docs/install-and-setup.md
用angular2和angularfirestore2创建一个有角度的小应用程序
我正在关注此链接: https://github.com/angular/angularfire2/blob/master/docs/install-and-setup.md
用angular2和angularfirestore2创建一个有角度的小应用程序
但是当我点击服务器时,我在浏览器控制台中收到以下错误..
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)
我试过谷歌搜索它,但没有找到确切的解决方案没有对我有用:(,
这是我遵循的:
1)已安装的节点版本8.9.1
2)npm install -g @ angular / cli – >版本1.5.2
3)新的’项目名’
4)npm install angularfire2 firebase –save
这是我的app.module.ts文件:
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:
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:
export const environment = { production: false,firebase: { apiKey: 'xxxxx',authDomain: 'aaaaaaa',databaseURL: 'bbbbbbbbbbbbbbbbbb',projectId: 'aaaaaaaaaaaaaa',storageBucket: 'aaaaaaaaaaaa',messagingSenderId: 'aaaaaaaaaaaaa' } };
然后ng服务,我收到上述错误..
您应该在app.module.ts中添加提供程序:[AngularFirestore]。
原文链接:https://www.f2er.com/angularjs/143809.html@NgModule({ imports: [ BrowserModule,providers: [AngularFirestore],bootstrap: [ AppComponent ] }) export class AppModule {}