@@ -56,7 +56,25 @@ npm install angularfire2 firebase --save
56
56
57
57
Now that you have a new project setup, install AngularFire2 and Firebase from npm.
58
58
59
- ### 4. Setup @NgModule for the AngularFireModule
59
+ ### 4. Add Firebase config to environments variable
60
+
61
+ Open ` /src/environments/environment.ts ` and add your Firebase configuration:
62
+
63
+ ``` ts
64
+ export const environment = {
65
+ production: false ,
66
+ firebase: {
67
+ apiKey: ' <your-key>' ,
68
+ authDomain: ' <your-project-authdomain>' ,
69
+ databaseURL: ' <your-database-URL>' ,
70
+ projectId: ' <your-project-id>' ,
71
+ storageBucket: ' <your-storage-bucket>' ,
72
+ messagingSenderId: ' <your-messaging-sender-id>'
73
+ }
74
+ };
75
+ ```
76
+
77
+ ### 5. Setup @NgModule for the AngularFireModule
60
78
61
79
Open ` /src/app/app.module.ts ` , inject the Firebase providers, and specify your Firebase configuration.
62
80
This can be found in your project at [ the Firebase Console] ( https://console.firebase.google.com ) :
@@ -66,20 +84,12 @@ import { BrowserModule } from '@angular/platform-browser';
66
84
import { NgModule } from ' @angular/core' ;
67
85
import { AppComponent } from ' ./app.component' ;
68
86
import { AngularFireModule } from ' angularfire2' ;
69
-
70
- // Must export the config
71
- export const firebaseConfig = {
72
- apiKey: ' <your-key>' ,
73
- authDomain: ' <your-project-authdomain>' ,
74
- databaseURL: ' <your-database-URL>' ,
75
- storageBucket: ' <your-storage-bucket>' ,
76
- messagingSenderId: ' <your-messaging-sender-id>'
77
- };
87
+ import { environment } from ' ../environments/environment' ;
78
88
79
89
@NgModule ({
80
90
imports: [
81
91
BrowserModule ,
82
- AngularFireModule .initializeApp (firebaseConfig )
92
+ AngularFireModule .initializeApp (environment . firebase )
83
93
],
84
94
declarations: [ AppComponent ],
85
95
bootstrap: [ AppComponent ]
@@ -95,15 +105,15 @@ You can optionally provide a custom FirebaseApp name with `initializeApp`.
95
105
@NgModule ({
96
106
imports: [
97
107
BrowserModule ,
98
- AngularFireModule .initializeApp (firebaseConfig , ' my-app-name' )
108
+ AngularFireModule .initializeApp (environment . firebase , ' my-app-name' )
99
109
],
100
110
declarations: [ AppComponent ],
101
111
bootstrap: [ AppComponent ]
102
112
})
103
113
export class AppModule {}
104
114
```
105
115
106
- ### 5 . Setup individual @NgModules
116
+ ### 6 . Setup individual @NgModules
107
117
108
118
After adding the AngularFireModule you also need to add modules for the individual @NgModules that your application needs.
109
119
- AngularFireAuthModule
@@ -122,20 +132,12 @@ import { AppComponent } from './app.component';
122
132
import { AngularFireModule } from ' angularfire2' ;
123
133
import { AngularFireDatabaseModule } from ' angularfire2/database' ;
124
134
import { AngularFireAuthModule } from ' angularfire2/auth' ;
125
-
126
- // Must export the config
127
- export const firebaseConfig = {
128
- apiKey: ' <your-key>' ,
129
- authDomain: ' <your-project-authdomain>' ,
130
- databaseURL: ' <your-database-URL>' ,
131
- storageBucket: ' <your-storage-bucket>' ,
132
- messagingSenderId: ' <your-messaging-sender-id>'
133
- };
135
+ import { environment } from ' ../environments/environment' ;
134
136
135
137
@NgModule ({
136
138
imports: [
137
139
BrowserModule ,
138
- AngularFireModule .initializeApp (firebaseConfig , ' my-app-name' ), // imports firebase/app needed for everything
140
+ AngularFireModule .initializeApp (environment . firebase , ' my-app-name' ), // imports firebase/app needed for everything
139
141
AngularFireDatabaseModule , // imports firebase/database, only needed for database features
140
142
AngularFireAuthModule , // imports firebase/auth, only needed for auth features
141
143
],
@@ -146,7 +148,7 @@ export class AppModule {}
146
148
147
149
```
148
150
149
- ### 6 . Inject AngularFireDatabase
151
+ ### 7 . Inject AngularFireDatabase
150
152
151
153
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):
152
154
@@ -167,7 +169,7 @@ export class AppComponent {
167
169
168
170
```
169
171
170
- ### 7 . Bind to a list
172
+ ### 8 . Bind to a list
171
173
172
174
In ` /src/app/app.component.ts ` :
173
175
@@ -198,7 +200,7 @@ Open `/src/app/app.component.html`:
198
200
</ul >
199
201
```
200
202
201
- ### 8 . Run your app
203
+ ### 9 . Run your app
202
204
203
205
``` bash
204
206
ng serve
0 commit comments