ionic tutorial - Ionic Toggle Class | Ionic - Toggle - ionic - ionic development - ionic 2 - ionic framework
- The Toggle Component is an on/off switch that can be used for a true/false variable in your application.
- A toggle technically is the same thing as an HTML checkbox input, except it looks different and is easier to use on a touch device. Toggles can also have colors assigned to them, by adding any color attribute.
- Sometimes there are two options available for users to choose. The most efficient way to handle these situations are toggle forms.
- Ionic gives us classes for toggle elements that are animated and easy to implement.
ionic tutorial . extension , ionic framework , ionic , ionic framework book , ionic app example , ionic templates , ionic getting started
Using Toggle
- Toggle can be implemented using two Ionic classes. First, we need to create label for the same reason we explained in last tutorial and assign toggle class to it.
- Inside our label will be created. You will notice two more ionic classes used in the example below. track class will add background styling to our checkbox and color animation when toggle is tapped. handle class is used to add circle button to it.
- This example shows two toggle forms. The first one is checked, the second one isn't.
- Above code will produce following screen
ionic tutorial . extension , ionic framework , ionic , ionic framework book , ionic app example , ionic templates , ionic getting started
Multiple Toggles
- Most of the time when you want to add more than one element of the same kind in Ionic, the best way is to use list items.
- The class that is used for multiple toggles is item-toggle. The next example shows how to create list with for toggles. First one and the second one is checked.
- Above code will produce following screen
Styling Toggle
- All Ionic color classes can be applied to toggle element. Prefix will be toggle. We will apply this to label element.
- below example shows all the colors applied.
- Above code will produce following screen