Simple CRUD (Create, Read, Update and Delete) using ionic 3 and Cloud firestore
In this project we are going to create the most simplest ionic CRUD (Create, Read, Update and Delete) using Cloud firestore.
You can find the full tutorial here
At the end of the tutorial above you'll be able to:
- Setup a firebase account.
- Configure firestore database permissions.
- Create an ionic app using ionic cli (command line tool).
- Create, Read, Update and Delete to a firestore database from an ionic app.
First, install Node.js. Then, install the latest Cordova and Ionic command-line tools in your terminal. Follow the Android and iOS platform guides to install required tools for development. For more info go here: https://ionicframework.com/getting-started.
npm install -g cordova ionic
Now lets create the ionic app
git clone https://github.com/jomendez/ionic-firestore-crud-example.git
cd ionic-firestore-crud-example
npm install
ionic serve
Go to https://console.firebase.google.com and login with your google account or create one.
Enter the name of the project and click on Add Firebase to your web app.
We are going to use this data to configure our project, this will allow us to connect to firebase.
Insert the config variable on the app.module.ts for that lets add the firebase dependency.
...
import * as firebase from 'firebase';
const config = {
apiKey: "<your key>",
authDomain: "<your key>",
databaseURL: "<your key>",
projectId: "<your key>",
storageBucket: "<your key>",
messagingSenderId: "<your key>"
};
firebase.initializeApp(config);
...
Next step is to configure Cloud Firestore, follow the following steps in the image, and start in test mode for now, to keep it simple.
For more rules you can visit here: https://cloud.google.com/firestore/docs/security/rules-query
Before we get into the ionic part, lets see how a firestore database structure looks like:
This example was taken from the ionAppFull4Pro ionic starter. In this example you can see that the firestore data model is based on collections and documents, and you can nest collection within documents:
for more details you can visit here https://firebase.google.com/docs/firestore/data-model.