Ionic2 Study Notes (8): Local storage& SQLite

Source: Internet
Author: User
Tags sqlite

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.