GreyOriginal address: http://www.cnblogs.com/greyzeng/p/5557947.html
?
? ??
? Ionic2 can have two ways of storing data, Local storage and SQLite
?
Localstorage
?
Because it is more accessible, it is not suitable for data that is more sensitive
For example, you can store: the user is logged in information. Some session information, etc.
Specific usage:
- Go to project directory: CD Myfirstapp
- set a button on the home page, click the button, get the Localstorage data and print it in the console
app/pages/home/home.html
in app/pages/home/ Add a processing method to the Home.ts:
We can through
this.local = new Storage (localstorage);
this.local.set (' IsLogin ', false);
and by:
this.local.get (' IsLogin ');
- Run: Ionic serve-l
Click the button and open the Chrome console to see the output:
?
Sqlite
We can also store data through SQLite, and use SQL statements to implement related storage.
- First we have to add a plugin: Go to project directory: CD Myfirstapp
Run:Ionic plugin add https://github.com/litehelpers/Cordova-sqlite-storage
- In App/app.ts, we initialize some of the database information first:
- Add a button and a label to the app/pages/home/home.html, and click the button to show the FirstName field people the first record of the table in the database dbname6:
App/pages/home/home.html
In App/pages/home/home.ts, add the appropriate method to get the data in the database:
- Run: Ionic serve-l
Click the ShowData button:
?
MORE: Use SQLite in Ionic 2 Instead of Local Storage
------
Previous post: Ionic2 study notes (7): Input
Ionic2 Study Notes (8): Local storage& SQLite