How to integrate Firebase with Angular 5 – AngularFire2 V5

Firebase is a mobile and web application development platform developed by Google. We can build our apps very fast, without making complex back-end system. It helps to scale automatically, for even the largest apps. In this Angular Firebase tutorial, we’re gonna go through the steps to integrate Firebase into Angular 5 App with AngularFire2 5.0.

I. Technology

– Angular 5
– AngularFire2 5.0

II. Step by Step

1. Set up the Firebase Project

Go to Firebase Console, login with your Google Account, then click on Add Project.

Enter Project name, select Country/Region:

angular-5-firebase-create-project

Press CREATE PROJECT, browser turns into:

angular-4-firebase-integration-add-firebase-project

Click on Add Firebase to your Web App, a Popup will be shown:

angular-5-firebase-create-project-add-firebase

Save the information for later usage.

Choose Database in the left (list of Firebase features) -> Tab RULES, then change .read and .write values to true:
angular-4-firebase-integration-firebase-project-db-config

2. Install AngularFire2

Before installing AngularFire2, make sure that we have latest version of Angular-cli installed. The lowest compatible version is 1.x.x-beta.14. We also need Typings, and TypeScript.

So, if you don’t have these things, try to install them:

2.1 Create Angular project

2.2 Install AngularFire2 and Firebase

3. Use AngularFire2 in Angular Project
3.1 Add Firebase config to environments variable

Open /src/environments/environment.ts, add your Firebase configuration that we have saved when Popup window was shown:

3.2 Setup @NgModule

Open /src/app/app.module.ts, import AngularFireModule and other AngularFire2 modules if necessary. Don’t forget specify Firebase configuration with AngularFireModule.initializeApp(firebaseConfig):

3.3 Use AngularFire module in Angular component

Open /src/app/app.component.ts:

/src/app/app.component.html:

III. Check Result

– Open browser with url http://localhost:4200/, enter Item content.
Item data displays immediately:

angular-5-firebase-demo

– Firebase Console Database:

angular-5-firebase-demo-console

IV. Source Code

Angular5Firebase

By grokonez | February 16, 2018.

Last updated on November 29, 2018.



Related Posts


3 thoughts on “How to integrate Firebase with Angular 5 – AngularFire2 V5”

  1. hi , i tried to this, i can write to DB,
    but cann’t read .
    2) there is a in the ending tag of pre ( i think this a typo.)
    3) can you help me how can i debug and understand why cann’t read from Db ( db rules are write and read = true)

  2. It works like a charm.Spend some time trying to make it work.Read useless materials(angular version not specified )
    thus the nightmare.
    Thanks.

Got Something To Say:

Your email address will not be published. Required fields are marked *

*