___|  _ \   |  |    |   |_ _|\ \     / ____|
 |     |   |  |  |    |   |  |  \ \   /  __|
 |   | |   | ___ __|  ___ |  |   \ \ /   |
\____|\___/     _|   _|  _|___|   \_/   _____| 

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

Ionic Tutorials: Setting Up Your In-App Settings for an Ionic app

BY: @yalzeee | CREATED: Jan. 18, 2019, 11:05 a.m. | VOTES: 115 | PAYOUT: $19.81 | [ VOTE ]

[IMAGE: https://cdn.steemitimages.com/DQmS4ho2iWke6Uc4wmNdSTD2GCtYJZFb7rRzMD2LLV49Dqs/ionic.jpg]
image source

Repository: Ionic Github Repository

Software Requirements:
Visual Studio Code(Or any preferred code editor),
npm, ionic.

What you will learn:
In this tutorial you would learn about how to manage your ionic app on whatever platform you choose to target covering these major concepts

Tutorial

Today, I would be coming back from my 3 week break with a new tutorial about how you could set up settings for your application.
In this tutorial we would be building a complete application from scratch.
Almost all applications give users options to change some parts of the application either embedded in the template or even part of the logic of the application. I did some research and this isn't properly taught on any free courses so i chose to show my reader how you could set up settings for your application using lifecycle events and storage memory for a local app. And you could also use your backend to sync settings for a user that may be using his account over multiple devices.

Lets get started...

Update Settings on Change

Start up a new ionic project with a tabs template like this

ionic start newProject tabs

Agree to all the prompts and then proceed to open your preferred editor in the folder that ionic just created.

Before we jump into this i would like to show you the life cycle events that we will be using for this tutorial. If you haven't been following my series
Lifecycle events are functions that are triggered automatically when a user is switching between views.

For this tutorial we would be using
-ionViewWillEnter: Triggered before a view Enters
-ionViewDidLoad: Triggered the first time the view loads.

For the purpose of this tutorial we would have to create some logic which we would like the user to be allowed to change. We would be making the user choose what content he would see on his homepage from the settings page.
Our app comes with the Home, About and Contact Tab. For this tutorial, we would be converting the About Tab to the settings tab.
Head over to the tabs.html document under the tabs folder and make this relevant changes.



  //Here i changed the icon for the tab and the name shown


You can now head to your home page and begin creating the template for a simple note taking app.
This would be the content of the homepage.



    My Note Taking App






      Add a new note









          Type Here








      {{ item }}




And you can then run ionic s which would run in our browser to show the template. As we can see for this tutorial we would be using a simple note taking application.

[IMAGE: https://cdn.steemitimages.com/DQmfSSmPxPUgtzWpsTLyyR1z8YfYvC8ZwVTwA1MG5i2hRu1/Screenshot%20(117).png]

Tip: You can easily open the chrome console using ctrl + J

Note: To get the storage to work you would need to update your app.module.ts file to know which storage to use like this.

import { IonicStorageModule } from '@ionic/storage';

@NgModule({
  declarations: [
    // ...
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    // ...
  ],
  providers: [
    // ...
  ]
})
export class AppModule {}

After that head to your home.ts file and add the logic that helps you collect these notes and store them on the devices storage.

import { Component } from '@angular/core';
import { NavController, AlertController, ActionSheetController,Platform } from 'ionic-angular';
import { Storage } from '@ionic/storage';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  note: string;
  notes = [];
  constructor(public storage: Storage , public actionSheetCtrl: ActionSheetController, public alertCtrl: AlertController, public navCtrl: NavController) {

  }
  ionViewDidLoad(){
    this.storage.get('notes').then(notes=>{
      if(notes){
      this.notes = notes;
    }
    })
  }
  addNote(){
    console.log(this.note);
    this.notes.push(this.note);
    this.note = '';
    this.storage.set('notes',this.notes)
  }
}

And with this we can get to adding settings. For the purpose of this tutorial we would be using settings to change the theme of the application and restrict who can add notes to this app by requiring a secret key.
Head to your setting tab and add a toggle for the light and dark theme and another for the restriction to a secret key.

```

  Settings







  Dark Theme






  Require Secret Key
TAGS: [ #utopian-io ] [ #tutorials ] [ #programming ] [ #stach ] [ #wafrica ]

Replies

@mcfarhat | Jan. 18, 2019, 1:26 p.m. | Votes: 15 | [ VOTE ]

Thank you for your contribution.
- Concepts shared in here do sound useful for anyone building ionic apps.
- It would be helpful to your readers to point other related prior tutorials you had made on ionic, indicating that this is part of a series.
- A gif would have been more useful in showing the results of adjusting the settings, or a before/after screenshot.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.

Need help? Chat with us on Discord.

[utopian-moderator]

@utopian-io | Jan. 20, 2019, 9:31 p.m. | Votes: 0 | [ VOTE ]

Thank you for your review, @mcfarhat! Keep up the good work!

@steem-ua | Jan. 18, 2019, 2:10 p.m. | Votes: 0 | [ VOTE ]

Hi @yalzeee!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

@utopian-io | Jan. 19, 2019, 4:54 a.m. | Votes: 0 | [ VOTE ]

Hey, @yalzeee!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

@steemitboard | Jan. 27, 2019, 12:12 a.m. | Votes: 0 | [ VOTE ]

Congratulations @yalzeee! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

https://steemitimages.com/60x70/http://steemitboard.com/@yalzeee/votes.png?201901262332You made more than 1750 upvotes. Your next target is to reach 2000 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

> Support SteemitBoard's project! Vote for its witness and get one more award!

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>