Contents

Welcome to the Mobiscroll API Reference. You can find the most up to date information about usage and customization options here.

Requires jQuery >= 1.7, Angular.js >= 1.0.8 (Supporting Angular 1.x)
Supported Platforms - Android 2.3+ including Android Oreo, iOS 5+ including iOS 11, Blackberry, Amazon Fire, Windows Phone 8+ and all major mobile and desktop browsers

Having trouble? Ask for help.


Getting Started with Mobiscroll for AngularJS

For getting started with Mobiscroll for Ionic 1 please follow this guide.

Mobiscroll is a collection of UI components that helps deliver great mobile apps, websites with a great user experience and in getting five-star app store reviews. The controls follow platform UX guidelines and can be styled with the Theme Builder for a perfect fit.

What is Angular JS?

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Learn more

What is the Mobiscroll Integration plugin and when to use it?

The Mobiscroll AngularJS Integration plugin is a set of Angularjs modules, which helps you using Mobiscroll with the Angularjs framework by providing directives that you can use out of the box.

As of version 2.14.0 the ng-model directive is fully supported and recommended to use with the mobiscroll directives. Check the reference!
The mobiscroll-options directive is deprecated. Use each control directive instead. (ex. mobiscroll-date)

Getting started with The Mobiscroll Angular integration

Here is an example of how to use the plugin in a common scenario

1. Download the plugin

When building your package select the AngularJS plugin on the download page. (don't forget to include the angular.js on your page header!)

2. Load the necessary scripts

Load order is essential. Make sure you load jQuery before Angular, and Mobiscroll after jQuery and Angular.
<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="js/mobiscroll.custom-2.17.3.min.js"></script>

3. Declare your module

When using the Mobiscroll Integrational plugin in your module, you have to set up the dependencies. If you are using the datetime scroller, then the dependency will be the 'mobiscroll-datetime' module.

var myModule = angular.module('myApp', ['mobiscroll-datetime']);

4. Add behavior to the module

Lets say you want to calculate someones age by entering his birthday (for this example our app is going to do this). We want to use the date scroller to input someones birthday, and then use a function of the scope to calculate his age.

myModule.controller('myController', ['$scope', function ($scope) { // create controller for the module
    // create function which calculates the age given the birthday as a datetime object
    $scope.age = function() {
        if (!$scope.birthday || $scope.birthday > new Date()) // if the birthday is not defined yet return 'undefined'
            return 'undefined';
        var now = new Date();
        return Math.round((now - $scope.birthday) / (100 * 60 * 60 * 24 * 365)) / 10; // calculate the age in years with one decimal
    };
}]);

5. Add markup

For our age calculator to work we will need an input field for the birthday and the paragraph which will tell us the information.

The angular model directive will take care of the model, and the mobiscroll date directive will take care of the rest.

<div ng-controller="myController">
    <input type="text" ng-model="birthday" mobiscroll-date />
    <p>Your age is {{age()}} years.</p>
</div>

And we're done! Whenever you click on the input the mobiscroll will pop up and ask for the birthday. When the birthday is set angular will evaluate the expression inside the {{ }} braces and the correct age will be shown. It's easy, isn't it?

Mobiscroll Directives Reference

Here will be listed the directives that come with the Angular JS integration plugin, with a few examples on how to use them.

Note: Currently all of the directives are restricted to attributes, since most of the mobiscroll components need an input or select tag to be initialized on.

Common attributes

Every scroller can be tuned to your needs, by the initialization options. When using angular you can use the same initialization as you would use in plain javascript, only you have to pass it via the mobiscroll controls attribute that you are using.

As of version 2.14.0 the mobiscroll-options directive is deprecated.
// you would do it like this in jQuery for date
$('input').mobiscroll().date({
    display: 'bubble',
    mode: 'mixed',
    theme: 'ios'
});
The above example using the mobiscroll-date directive in angular
// you would do it like this in angular
<input type="text" ng-model="birthday" mobiscroll-date="{ display: 'bubble', mode: 'mixed', theme: 'ios' }" />

Calling instance methods

Directive Type Description
mobiscroll-instance string Attribute for the mobiscroll instance.

Gives access to the mobiscroll instance without querying the element.

When added to the element a mobiscroll is initialized on, sets the initialized mobiscroll instance into the current scope property provided.

Example showing mobiscroll on button click

<div ng-controller="myController">
    <input id="birth" ng-model="birthday" mobiscroll-datetime mobiscroll-instance="birthdayInstance" type="text"/>
    <button ng-click="showTheScroller()">Show<button/>
</div>

This way you can access the mobiscroll datetime instance inside myController

// ... 
.controller('myController', ['$scope', function ($scope) {
    $scope.showTheScroller = function () {
        $scope.birthdayInstance.show(); // calling the instance show method
    };
}]);

Global Settings

$.mobiscroll.setDefaults(options)

Description

The global mobiscroll object is the place where you can set all the options that you'll be needing across your application or page. It should contain the settings that need to be the same across all components.

Example
// Sets the theme to iOS and localization to German
$.mobiscroll.setDefaults({
    theme: 'ios',
    lang: 'de'
});

For more examples check out the demo page.