@@ -118,6 +118,7 @@ export class AppModule {}
118
118
### 6. Setup individual @NgModules
119
119
120
120
After adding the AngularFireModule you also need to add modules for the individual @NgModules that your application needs.
121
+ - AngularFirestoreModule
121
122
- AngularFireAuthModule
122
123
- AngularFireDatabaseModule
123
124
- AngularFireStorageModule (Future release)
@@ -132,15 +133,15 @@ import { BrowserModule } from '@angular/platform-browser';
132
133
import { NgModule } from ' @angular/core' ;
133
134
import { AppComponent } from ' ./app.component' ;
134
135
import { AngularFireModule } from ' angularfire2' ;
135
- import { AngularFireDatabaseModule } from ' angularfire2/database ' ;
136
+ import { AngularFirestoreModule } from ' angularfire2/firestore ' ;
136
137
import { AngularFireAuthModule } from ' angularfire2/auth' ;
137
138
import { environment } from ' ../environments/environment' ;
138
139
139
140
@NgModule ({
140
141
imports: [
141
142
BrowserModule ,
142
143
AngularFireModule .initializeApp (environment .firebase , ' my-app-name' ), // imports firebase/app needed for everything
143
- AngularFireDatabaseModule , // imports firebase/database , only needed for database features
144
+ AngularFirestoreModule , // imports firebase/firestore , only needed for database features
144
145
AngularFireAuthModule , // imports firebase/auth, only needed for auth features
145
146
],
146
147
declarations: [ AppComponent ],
@@ -150,21 +151,21 @@ export class AppModule {}
150
151
151
152
```
152
153
153
- ### 7. Inject AngularFireDatabase
154
+ ### 7. Inject AngularFirestore
154
155
155
156
Open ` /src/app/app.component.ts ` , and make sure to modify/delete any tests to get the sample working (tests are still important, you know):
156
157
157
158
``` ts
158
159
import { Component } from ' @angular/core' ;
159
- import { AngularFireDatabase , FirebaseListObservable } from ' angularfire2/database ' ;
160
+ import { AngularFirestore } from ' angularfire2/firestore ' ;
160
161
161
162
@Component ({
162
163
selector: ' app-root' ,
163
164
templateUrl: ' app.component.html' ,
164
165
styleUrls: [' app.component.css' ]
165
166
})
166
167
export class AppComponent {
167
- constructor (db : AngularFireDatabase ) {
168
+ constructor (db : AngularFirestore ) {
168
169
169
170
}
170
171
}
@@ -177,17 +178,18 @@ In `/src/app/app.component.ts`:
177
178
178
179
``` ts
179
180
import { Component } from ' @angular/core' ;
180
- import { AngularFireDatabase , FirebaseListObservable } from ' angularfire2/database' ;
181
+ import { AngularFirestore } from ' angularfire2/firestore' ;
182
+ import { Observable } from ' rxjs/Observable' ;
181
183
182
184
@Component ({
183
185
selector: ' app-root' ,
184
186
templateUrl: ' app.component.html' ,
185
187
styleUrls: [' app.component.css' ]
186
188
})
187
189
export class AppComponent {
188
- items: FirebaseListObservable <any []>;
189
- constructor (db : AngularFireDatabase ) {
190
- this .items = db .list ( ' / items' );
190
+ items: Observable <any []>;
191
+ constructor (db : AngularFirestore ) {
192
+ this .items = db .collection ( ' items' ). valueChanges ( );
191
193
}
192
194
}
193
195
```
@@ -197,7 +199,7 @@ Open `/src/app/app.component.html`:
197
199
``` html
198
200
<ul >
199
201
<li class =" text" *ngFor =" let item of items | async" >
200
- {{item.$value }}
202
+ {{item.name }}
201
203
</li >
202
204
</ul >
203
205
```
@@ -212,35 +214,4 @@ Run the serve command and go to `localhost:4200` in your browser.
212
214
213
215
And that's it! If it's totally * borked* , file an issue and let us know.
214
216
215
- ### [ Next Step: Retrieving data as objects] ( 2-retrieving-data-as-objects.md )
216
-
217
- ### Troubleshooting
218
-
219
- #### 1. Cannot find namespace 'firebase'.
220
-
221
- If you run into this error while trying to invoke ` ng serve ` , open ` src/tsconfig.json ` and add the "types" array as follows:
222
-
223
- ``` json
224
- {
225
- "compilerOptions" : {
226
- ...
227
- "typeRoots" : [
228
- " ../node_modules/@types"
229
- ],
230
-
231
- // ADD THIS
232
- "types" : [
233
- " firebase"
234
- ]
235
- }
236
- }
237
- ```
238
-
239
- #### 2. Cannot find name 'require' (This is just a temporary workaround for the Angular CLI).
240
-
241
- If you run into this error while trying to invoke ` ng serve ` , open ` src/typings.d.ts ` and add the following two entries as follows:
242
-
243
- ``` bash
244
- declare var require: any;
245
- declare var module: any;
246
- ```
217
+ ### [ Next Step: Understanding collections in Firestore] ( firestore/collections.md )
0 commit comments