How to integrate Firebase with Angular 4

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 4 Firebase tutorial, we’re gonna go through the steps to integrate Firebase into Angular 4 App with AngularFire2 4.0.

I. Technology

– Angular 4
– AngularFire2 4.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:

Press CREATE PROJECT, browser turns into:

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

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:

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:


III. Check Result

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

– Firebase Console Database:

IV. Source Code


Related Posts

Got Something To Say:

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