Ionic Framework is one of the best framework for developing hybrid mobile apps with HTML5. Based on AngularJS the set of available features is tremendous. This post presents, with examples, some of the best hidden features provided.
Scroll
Infinite Scroll
The ionInfiniteScroll directive allows you to call a function whenever the user gets to the bottom of the page or near the bottom of the page.
See the Pen Infinite Scroll: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
List
Collection repeat
The collection-repeat directive is a directive that allows you to render lists with thousands of items in them, and experience little to no performance penalty.
See the Pen collection-repeat: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
Gesture
Events
The gesture service has only two methods, on
adds an event listener for an DOM element and off
removes it. While AngularJS ngTouch provides only three touch events (ngClick, ngSwipeLeft and ngSwipeRight) $ionicGesture provides dozens (hold, tap, doubletap, drag, dragstart etc.).
See the Pen Ionic $ionicGesture example: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
Dom manipulation
If you are accustomed to AngularJS I am sure that you experienced some difficulties when manipulating the DOM. JQlite helps but is itself very limited. Ionic provides some methods to help you deal with it.
ionic.DomUtil.ready
Call a function when the DOM is ready, or if it is already ready call the function immediately.
See the Pen ionic.DomUtil.ready Example by Julien Renaux (@shprink) on CodePen.
ionic.DomUtil.getParentWithClass
Returns the closest parent of element matching the className, or null.
See the Pen ionic.DomUtil.getParentWithClass Example: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
Utilities
ionic.throttle
Only call a function once in the given interval. In this example the function should be called half as many as we tried.
See the Pen Ionic Throttle example: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
ionic.debounce
Only call a function once in the given interval, the timer is reset on every call. In this example the function should never be called.
See the Pen Ionic Debounce example: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
ionic.Utils.arrayMove
Really useful function that manipulates array items position.
See the Pen Ionic arrayMove example: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
Tabs
Starting from ionic beta.14 we can select the position of the tabs through configuration.
Tabs top
.config(function($ionicConfigProvider){ $ionicConfigProvider.tabs.position('top'); })
See the Pen Tabs Top: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
Tabs bottom
.config(function($ionicConfigProvider){ $ionicConfigProvider.tabs.position('bottom'); })
See the Pen Tabs bottom: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.
Delegation
Delegation allow you to have several instances of the same component within the same view. You have this capability on ion-side-menus, ion-tabs,ion-scroll ion-content, ion-list and ion-slide-box using the delegate-handle
directive attribute.
See the Pen Ionic Side Menu delegation: 1.0.0-beta.14 by Julien Renaux (@shprink) on CodePen.