Working with SQlite in ionic 2 rc3

In this tutorial we are are using sqlite in ionic 2 rc3. Rc3 was released with solving several bugs and added some new features. checkout new features https://github.com/driftyco/ionic/releases/tag/v2.0.0-rc.3

Before We start make sure your ionic is updated with ionic 2 rc 3.
If not then update ionic with following command

Let’s start with creating fresh new ionic 2 project

Adding platform

Note:  that if you have to make ios app then you required mac.

Got to project folder

After that install SQLite plugin

In this example we are storing users firstname and lastname in to sqlite database called people and also retrieving data from sqlite

Open home.ts from pages

First import “SQLite” dependency in page from ionic-native

Above code we have constructor() in which we are creating table if not exist. “Make sure use SQLite after the platform ready”

After that there is add() function for adding firstname and lastname for person in sqlite database

At the end refresh() function we are responsible for loading person data from sqlite database

Let’s move to html part

Here we have created two module called firstname and lastname of type text. There is one button “insert” on click add() function will be execute from home.ts

*ngfor are using for retrieving peoples information one by one in people and then displaying in ion-item

Let’s Build App

Output

4 Comments

Leave a Reply