ngCordova provides several types of modal window, of course depending on a smart device environment. I will try to show you every single one of them.

Note: If this tutorial was helpful, need further clarification, something is not working or do you have a request for another Ionic post? Furthermore, if you don't like something about this blog, if something is bugging you, don't like how I'm doing stuff here, again leave me a comment below. I'm here to help you, I expect the same from you. Feel free to comment below, subscribe to my blog, mail me to, or follow and mention me on twitter (@gajotres). Thanks and have a nice day!

PS. If you want my help, if possible (even if it takes you some time to do that), create a working example I can play with. Use Plunker for AngularJS based questions or jsFiddle for jQuery/jQuery Mobile based questions.


Table of Contents

Click here if you want to see other tutorials, or articles about the Ionic framework (themes, templates, plugins, tutorials)


Before we can do anything make sure you have the following:
  • Android Environment (or iOS if your working on a MacOS)
  • nodeJS
  • Ionic
  • Cordova
If you don’t have a preset Ionic + Android environment, find more information here: Ionic Framework | Installation Guide.

1. Update Ionic & Cordova

First thing first, you should update nodeJS to the latest version. Without it we wouldn’t be able to update correctly to latest Ionic and Cordova.
Next, update Ionic and Cordova, older versions may not work with this tutorial:
npm update -g cordova ionic

2. Create a New Project

ionic start IonicModalsDemo blank
cd IonicModalsDemo
Warning: Since some of you never worked with Ionic CLI. From this point and further, every time I tell you to execute something, do that inside a project folder.
Because we’re working with Android, we need to add necessary files it to our project:
ionic platform add android
For MacOS users, do it like this:
ionic platform add ios

3. Download ngCordova archive

ngCordova is a collection of 63+ AngularJS extensions on top of the Cordova API that make it easy to build, test, and deploy Cordova mobile apps with AngularJS. While we can make this work without ngCordova, it’s much more practical this way. This collection also holds many Ionic Framework compatible plugins.
Download ngCordova zip file, here’s site link:
Official Site Docs Download Link
Unzip this archive, find a file name called: ng-cordova.min.js, it should be available at this location: ng-cordova-master\dist\.
Open your newly created project directory and copy ng-cordova.min.js to this location: IonicModalsDemo\www\js.
Now include this location to index.html located at IonicModalsDemo\www; add it above cordova.js file, like this:
<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>

4. Include Cordova Plugins

Add required plugin:
cordova plugin add
cordova plugin add org.apache.cordova.dialogs
cordova plugin add
cordova plugin add
cordova plugin add
cordova plugin add cordova-plugin-whitelist
Install Whitelist plugin only if you’re using Cordova 4.0 +. Without it you’ll receive “Application Error: There was a network error.” error.
One note, some of these plugins may not work with Cordova 5.1.1, it’s an internal Cordova error. So use any other Cordova version. If you already have version 5.1.1, do this:
npm uninstall -g cordova
npm install -g cordova@5.0.0


At this point, you should have everything set up and ready, we can start working on our example.
Go to IonicModalsDemo project directory and find app.js, alter angular.module line and include ngCordova service, like this:
var app = angular.module('starter', ['ionic', 'ngCordova'])
Open index.html file, add a controller to ion-content directive:
      <ion-header-bar class="bar-stable">
        <h1 class="title"Modals Example</h1>
      <ion-content ng-controller="ModalsController">

Initialize this controller in app.js file; don’t forget to inject these services:
app.controller('ModalsController', function($scope, $cordovaActionSheet, $cordovaDialogs, $cordovaPinDialog, $cordovaSpinnerDialog, $cordovaToast) {

If you’re using Cordova 4+, you will need to check if there’s a Whitelist plugin installed with your project. If you have it, add this security meta tag to your index.html HEAD content:
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">
Without it your application will throw an error during the app initialization, after that it will continually throwing no security meta-tag found. While not a blocking point, constant console log warnings will make it hard to do any debugging.
Show an Action Sheet:
$scope.showActionSheet = function() {
	var options = {
		title: 'What do you want with this image?',
		buttonLabels: ['Share via Facebook', 'Share via Twitter'],
		addCancelButtonWithLabel: 'Cancel',
		androidEnableCancelButton : true,
		winphoneEnableCancelButton : true,
		addDestructiveButtonWithLabel : 'Delete it'

		.then(function(btnIndex) {
			var index = btnIndex;
Show a dialog:
$scope.showDialog = function() {		
	$cordovaDialogs.confirm('Do you like cats?', 'Question', ['Yes','No'])
		.then(function(buttonIndex) {
		  // no button = 0, 'OK' = 1, 'Cancel' = 2
		  var btnIndex = buttonIndex;
Show a pin dialog:
$scope.showPinDialog = function() {		
	$cordovaPinDialog.prompt('Some message here').then(
		function(result) {
			console.log('Entered value : ' + result.input1);
		function (error) {
Show a spinner dialog:
$scope.showSpinnerDialog = function() {		
	$"Warning","Self destruct imminent!", true);
	}, 3000);
Show a toast:
$scope.showToast = function() {		
		.show("Here's a message", 'short', 'center')
		.then(function(success) {
		}, function (error) {


This is what our application looks like:


Application main page.
<!DOCTYPE html>
    <meta charset="utf-8">
    <meta http-equiv="Content-Security-Policy" content="default-src *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src  'self' 'unsafe-inline' *">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <!-- cordova script (this will be a 404 during development) -->
    <script src="js/ng-cordova.min.js"></script>    
    <script src="cordova.js"></script>
    <!-- your app's js -->
    <script src="js/app.js"></script>
  <body ng-app="starter">
        <ion-header-bar class="bar-stable">
            <h1 class="title">Modal examples</h1>
        <ion-content ng-controller="ModalsController">
			<button class="button button-full button-positive" ng-click="showActionSheet()">
			  Open the Action Sheet
            <button class="button button-full button-positive" ng-click="showDialog()">
			  Open the Dialog
			<button class="button button-full button-positive" ng-click="showPinDialog()">
			  Open the Pin Dialog
			<button class="button button-full button-positive" ng-click="showSpinnerDialog()">
			  Open the Spinner Dialog
			<button class="button button-full button-positive" ng-click="showToast()">
			  Open the Toast
Continue to the next page

  • VL Cheong

    Hi, nice article. I’ve a question, is this application must run on a simulator ? because when I tried to run on my browser, I got error Cannot read property ‘spinnerDialog’ of undefined.

    • This error usually means two things. Either plugin is not installed or there was an error during the installation and you must remove it and add it again.