Book Image

Ionic Cookbook

By : Hoc Phan
Book Image

Ionic Cookbook

By: Hoc Phan

Overview of this book

Table of Contents (18 chapters)
Ionic Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Saving array data to Firebase


Sending and saving data to the Firebase backend server is as simple as calling the $add() function. Firebase automatically handles all the REST operations so that you don't have to call via the $http services or create your own. From a frontend developer's perspective, you can treat your data as a typical JavaScript object.

In this recipe, you will learn how to make connections to Firebase by creating a reference object and adding data into the object in the array format. Firebase treats an array like an object. The only difference is that each array's item will have an integer key. Here's an example:

// When we send this
['a', 'b', 'c', 'd', 'e']
// Firebase stores this
{0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e'}

Getting ready

You should log in to your Firebase dashboard ahead of time and navigate to the Data tab. The code will create a node called items to store data. You need to make sure that there is no existing items node, in case you created one before.

How to...