@@ -142,7 +142,7 @@ and add the following three entries.
142142
143143your ` app.module.ts ` file should look something like this.
144144
145- ``` bash
145+ ``` ts
146146
147147import { NgModule } from ' @angular/core' ;
148148import { IonicApp , IonicModule } from ' ionic-angular' ;
@@ -190,7 +190,7 @@ Now inject AngularFireDatabase in your component. Open your `home.ts` by going i
190190
191191Your ` home.ts ` file should look like this.
192192
193- ` ` ` bash
193+ ``` ts
194194
195195import { Component } from ' @angular/core' ;
196196import { NavController } from ' ionic-angular' ;
@@ -215,7 +215,7 @@ export class HomePage {
215215
216216** Update** your ` home.html ` at ` src/pages/home/home.html ` , with following entry
217217
218- ` ` ` bash
218+ ``` html
219219
220220<ion-header >
221221 <ion-navbar >
@@ -259,21 +259,20 @@ C:\projects\Ionic_AngularFire2_Project> ionic g provider AuthService
259259This should create the AuthService under ` src/providers/auth-service.ts ` .
260260Update the service with the following code.
261261
262- ` ` ` bash
262+ ``` typescript
263263import { Observable } from ' rxjs/Observable' ;
264264import { Injectable } from ' @angular/core' ;
265265import { AngularFireAuth } from ' angularfire2/auth' ;
266- import { User } from ' firebase' ;
267- import { FacebookAuthProvider } from ' firebase/auth' ;
266+ import * as firebase from ' firebase/app' ;
268267
269268@Injectable ()
270269export class AuthService {
271- private authState: Observable< User> ;
272- private currentUser: User;
270+ private authState: Observable <firebase . User >;
271+ private currentUser: firebase . User ;
273272
274273 constructor (public afAuth$ : AngularFireAuth ) {
275274 this .authState = afAuth$ .authState ;
276- afAuth$.subscribe(( user: User) => {
275+ afAuth$ .subscribe ((user : firebase . User ) => {
277276 this .currentUser = user ;
278277 });
279278 }
@@ -283,7 +282,7 @@ export class AuthService {
283282 }
284283
285284 signInWithFacebook(): firebase .Promise <FirebaseAuthState > {
286- return this.afAuth$.auth.signInWithPopup(new FacebookAuthProvider()) ;
285+ return this .afAuth$ .auth .signInWithPopup (new firebase . auth . FacebookAuthProvider ());
287286 }
288287
289288 signOut(): void {
@@ -303,7 +302,7 @@ export class AuthService {
303302
304303Add your service in ` app.module.ts ` . Your ` app.module.ts ` should look like this
305304
306- ` ` ` bash
305+ ``` ts
307306
308307import { NgModule } from ' @angular/core' ;
309308import { IonicApp , IonicModule } from ' ionic-angular' ;
@@ -344,7 +343,7 @@ export class AppModule { }
344343
345344Update your ` home.html ` to add a login button. Your ` home.html ` should look like this
346345
347- ` ` ` bash
346+ ``` html
348347
349348<ion-header >
350349 <ion-navbar >
@@ -369,7 +368,7 @@ Update your `home.html` to add a login button. Your `home.html` should look like
369368and finally, add the corresponding click handlers in ` home.ts ` as follows.
370369Also, ensure the * AuthService* is injected in the constructor. Your ` home.ts ` should look like this
371370
372- ` ` ` bash
371+ ``` ts
373372
374373import { Component } from ' @angular/core' ;
375374import { NavController } from ' ionic-angular' ;
@@ -457,7 +456,7 @@ Add the platform to your facebook portal as mentioned in the document [here](htt
457456
458457Now import the Platform and Facebook objects in your ``` auth-service.ts ```
459458
460- ` ` `
459+ ``` ts
461460import { Platform } from ' ionic-angular' ;
462461import { Facebook } from ' ionic-native' ;
463462```
@@ -470,19 +469,19 @@ your ```auth-service.ts``` code should look like this.
470469import { Observable } from ' rxjs/Observable' ;
471470import { Injectable } from ' @angular/core' ;
472471import { AngularFireAuth } from ' angularfire2/auth' ;
473- import { User } from ' firebase' ;
474- import { FacebookAuthProvider } from ' firebase/auth ' ;
472+ import * as firebase from ' firebase/app ' ;
473+
475474import { Platform } from ' ionic-angular' ;
476475import { Facebook } from ' ionic-native' ;
477476
478477@Injectable ()
479478export class AuthService {
480- private authState: Observable< User> ;
481- private currentUser: User;
479+ private authState: Observable <firebase . User >;
480+ private currentUser: firebase . User ;
482481
483482 constructor (public afAuth$ : AngularFireAuth ) {
484483 this .authState = afAuth$ .authState ;
485- afAuth$.subscribe(( user: User) => {
484+ afAuth$ .subscribe ((user : firebase . User ) => {
486485 this .currentUser = user ;
487486 });
488487 }
@@ -495,10 +494,10 @@ export class AuthService {
495494 if (this .platform .is (' cordova' )) {
496495 return Facebook .login ([' email' , ' public_profile' ]).then (res => {
497496 const facebookCredential = firebase .auth .FacebookAuthProvider .credential (res .authResponse .accessToken );
498- return this.afAuth$.aut .signInWithCredential(facebookCredential);
497+ return this .afAuth$ .auth .signInWithCredential (facebookCredential );
499498 });
500499 } else {
501- return this.afAuth$.auth.signInWithPopup(new FacebookAuthProvider ());
500+ return this .afAuth$ .auth .signInWithPopup (new firebase . auth . FacebookAuthProvider ());
502501 }
503502
504503 }
0 commit comments