1
- # Using AngularFire2 with Ionic 2
1
+ # Using AngularFire with Ionic 2
2
2
3
- This document provides you a walkthrough of integrating AngularFire2 Authentication with Ionic2.
3
+ This document provides you a walkthrough of integrating AngularFire Authentication with Ionic2.
4
4
The below setup has been tested on Windows 10, but it should be same for Mac/Linux.
5
5
6
6
Ensure that you're executing these commands as ** Administrator** on Windows and ** sudo** on Mac/Linux to avoid any errors.
@@ -59,28 +59,28 @@ C:\projects>ionic -v
59
59
60
60
These are the latest versions as of writting this document.
61
61
62
- On successful execution of above commands, you're all set to create your Ionic 2 app.
62
+ On successful execution of above commands, you're all set to create your Ionic app.
63
63
To create your app, change into the directory where you want your app to reside and execute the following command
64
64
65
65
``` bash
66
66
67
- C:\p rojects> ionic start Ionic_AngularFire2_Project blank --v2
67
+ C:\p rojects> ionic start Ionic_AngularFire_Project blank --v2
68
68
69
69
```
70
70
71
- > The command ionic start will create the project with name "Ionic_AngularFire2_Project " using "blank" template.
71
+ > The command ionic start will create the project with name "Ionic_AngularFire_Project " using "blank" template.
72
72
73
73
> The --v2 flag ensures, this is a Ionic2 project.
74
74
75
75
Change to the project directory, which was just created with above command
76
76
77
- > C:\projects\Ionic_AngularFire2_Project >
77
+ > C:\projects\Ionic_AngularFire_Project >
78
78
79
79
To start your app, execute the following command
80
80
81
81
``` bash
82
82
83
- C:\p rojects\I onic_AngularFire2_Project > ionic serve
83
+ C:\p rojects\I onic_AngularFire_Project > ionic serve
84
84
85
85
```
86
86
@@ -95,37 +95,37 @@ external libraries and extend this application.
95
95
96
96
``` bash
97
97
98
- C:\p rojects\I onic_AngularFire2_Project > npm install -g typings
98
+ C:\p rojects\I onic_AngularFire_Project > npm install -g typings
99
99
100
- C:\p rojects\I onic_AngularFire2_Project > npm install -g typescript
100
+ C:\p rojects\I onic_AngularFire_Project > npm install -g typescript
101
101
102
102
```
103
103
104
104
Check typings and typescript versions by executing following commands:
105
105
106
106
``` bash
107
107
108
- C:\p rojects\I onic_AngularFire2_Project > typings -v
108
+ C:\p rojects\I onic_AngularFire_Project > typings -v
109
109
2.0.0
110
110
111
- C:\p rojects\I onic_AngularFire2_Project > tsc -v
111
+ C:\p rojects\I onic_AngularFire_Project > tsc -v
112
112
Version 2.0.10
113
113
114
114
```
115
115
116
- ### Configuring AngularFire2 and Firebase
116
+ ### Configuring AngularFire and Firebase
117
117
118
- Install angularfire2 and firebase by executing the following command in your project directory
118
+ Install AngularFire and firebase by executing the following command in your project directory
119
119
120
120
``` ts
121
121
122
- C :\projects \Ionic_AngularFire2_Project > npm install angularfire2 firebase -- save
122
+ C :\projects \Ionic_AngularFire_Project > npm install AngularFire firebase -- save
123
123
124
124
```
125
125
126
- _ This should add angularfire2 and firebase entry in your project's package.json file in dependencies section. Something similar_
126
+ _ This should add AngularFire and firebase entry in your project's package.json file in dependencies section. Something similar_
127
127
128
- > "angularfire2 ": "^2.0.0-beta.6",
128
+ > "AngularFire ": "^2.0.0-beta.6",
129
129
130
130
> "firebase": "^3.6.1",
131
131
@@ -149,7 +149,7 @@ import { IonicApp, IonicModule } from 'ionic-angular';
149
149
import { MyApp } from ' ./app.component' ;
150
150
import { HomePage } from ' ../pages/home/home' ;
151
151
152
- import { AngularFireModule } from ' angularfire2 ' ;
152
+ import { AngularFireModule } from ' AngularFire ' ;
153
153
154
154
export const firebaseConfig = {
155
155
apiKey: " xxxxxxxxxx" ,
@@ -195,7 +195,7 @@ Your `home.ts` file should look like this.
195
195
import { Component } from ' @angular/core' ;
196
196
import { NavController } from ' ionic-angular' ;
197
197
198
- import { AngularFireDatabase , FirebaseListObservable } from ' angularfire2 /database' ;
198
+ import { AngularFireDatabase , FirebaseListObservable } from ' AngularFire /database' ;
199
199
200
200
@Component ({
201
201
selector: ' page-home' ,
@@ -239,20 +239,20 @@ export class HomePage {
239
239
240
240
``` bash
241
241
242
- C:\p rojects\I onic_AngularFire2_Project > ionic serve
242
+ C:\p rojects\I onic_AngularFire_Project > ionic serve
243
243
244
244
```
245
245
246
246
This should fetch the data from firebase.
247
247
248
- ## Configuring AngularFire2 Auth with Ionic2
248
+ ## Configuring AngularFire Auth with Ionic2
249
249
250
250
Continuing with the above example stop your server by pressing ` ctrl+c ` and go to command prompt and
251
251
generate a service by executing the following command
252
252
253
253
``` bash
254
254
255
- C:\p rojects\I onic_AngularFire2_Project > ionic g provider AuthService
255
+ C:\p rojects\I onic_AngularFire_Project > ionic g provider AuthService
256
256
257
257
```
258
258
@@ -262,7 +262,7 @@ Update the service with the following code.
262
262
``` typescript
263
263
import { Observable } from ' rxjs/Observable' ;
264
264
import { Injectable } from ' @angular/core' ;
265
- import { AngularFireAuth } from ' angularfire2 /auth' ;
265
+ import { AngularFireAuth } from ' AngularFire /auth' ;
266
266
// Do not import from 'firebase' as you'll lose the tree shaking benefits
267
267
import * as firebase from ' firebase/app' ;
268
268
@@ -306,7 +306,7 @@ import { IonicApp, IonicModule } from 'ionic-angular';
306
306
import { MyApp } from ' ./app.component' ;
307
307
import { HomePage } from ' ../pages/home/home' ;
308
308
309
- import { AngularFireModule } from ' angularfire2 ' ;
309
+ import { AngularFireModule } from ' AngularFire ' ;
310
310
import { AuthService } from ' ../providers/auth-service' ;
311
311
312
312
@@ -371,7 +371,7 @@ import { Component } from '@angular/core';
371
371
import { NavController } from ' ionic-angular' ;
372
372
373
373
import { AuthService } from ' ../../providers/auth-service' ;
374
- import { AngularFireDatabase , FirebaseListObservable } from ' angularfire2 /database' ;
374
+ import { AngularFireDatabase , FirebaseListObservable } from ' AngularFire /database' ;
375
375
376
376
@Component ({
377
377
selector: ' page-home' ,
@@ -412,7 +412,7 @@ Ensure you've the platform added to your project. If not add the platform by exe
412
412
413
413
```
414
414
415
- C:\projects\Ionic_AngularFire2_Project >ionic platform add android
415
+ C:\projects\Ionic_AngularFire_Project >ionic platform add android
416
416
417
417
```
418
418
@@ -423,7 +423,7 @@ Now, let's try to run the app in browser. Execute the command
423
423
424
424
```
425
425
426
- C:\projects\Ionic_AngularFire2_Project > ionic run android
426
+ C:\projects\Ionic_AngularFire_Project > ionic run android
427
427
428
428
```
429
429
@@ -440,7 +440,7 @@ _Ensure you follow the steps correctly to configure your app._
440
440
Once you create your app and make a note of your App ID, go to command prompt in your project directory and execute the following command
441
441
442
442
```
443
- C:\projects\Ionic_AngularFire2_Project >
443
+ C:\projects\Ionic_AngularFire_Project >
444
444
ionic plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApp"
445
445
446
446
```
@@ -465,7 +465,7 @@ your ```auth-service.ts``` code should look like this.
465
465
``` ts
466
466
import { Observable } from ' rxjs/Observable' ;
467
467
import { Injectable } from ' @angular/core' ;
468
- import { AngularFireAuth } from ' angularfire2 /auth' ;
468
+ import { AngularFireAuth } from ' AngularFire /auth' ;
469
469
// Do not import from 'firebase' as you'll lose the tree shaking benefits
470
470
import * as firebase from ' firebase/app' ;
471
471
@@ -516,15 +516,15 @@ Verfiy your app is running in browser by executing the following command
516
516
517
517
```
518
518
519
- C:\projects\Ionic_AngularFire2_Project >ionic serve
519
+ C:\projects\Ionic_AngularFire_Project >ionic serve
520
520
521
521
```
522
522
523
523
Everything should work. Now trying running the app on your android phone
524
524
525
525
```
526
526
527
- C:\projects\Ionic_AngularFire2_Project > ionic run android
527
+ C:\projects\Ionic_AngularFire_Project > ionic run android
528
528
529
529
```
530
530
0 commit comments