im像这样导入Angularfirestore
x[i]
其显示错误错误:无法找到模块“ @ angular / fire / firestore”。
import { AngularFirestore } from '@angular/fire/firestore';
app.module.ts
"firebase": "^4.13.1",
"angularfire2": "^5.0.0-rc.4",
"rxjs": "^6.0.0",
"rxjs-compat": "^6.1.0",
答案 0 :(得分:2)
您已经安装了命令
npm install firebase angularfire2
AngularFirestore的导入是
import { AngularFirestore } from 'angularfire2/firestore';
您的app.module具有如下导入:〜
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { environment } from '../environments/environment';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule.enablePersistence()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
您将要使用以下导入功能将AngularFirestore注入到组件中:
import { Component } from '@angular/core';
import { AngularFirestore } from 'angularfire2/firestore';
@Component({ ... })
export class AppComponent {
constructor(private afs: AngularFirestore) {
// ...
}
}
您的enviornment.ts
可以像下面这样配置您的Firebase:〜
在您的情况下,其import { firebaseConfig } from './credentials';
export const environment = {
production: false,
firebase: {
apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
authDomain: 'your-project-id.firebaseapp.com',
databaseURL: 'https://your-project-id.firebaseio.com',
projectId: 'your-project-id',
storageBucket: 'your-project-id.appspot.com',
messagingSenderId: 'XXXXXXXXXXXX'
}
};