Skip to content

Instantly share code, notes, and snippets.

@rajatrocks
rajatrocks / Ionic Cordova Toast
Created October 31, 2014 04:10
Angular factory to show either Cordova Toast plugin or a self-closing Ionic popup, so that you can develop with Toast on web and on device
// Requires the Toast plugin: https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin
// And Ionic Framework: http://ionicframework.com
// ngCordova is used here, but easily removed: http://ngcordova.com/
// When running in Cordova, show the native toast. Outside of Cordova, show an Ionic Popup for the same period of time.
// Uses the API for the Toast plugin - message, duration, position.
// Differences are that: Ionic Popup ignores position, and doesn't allow doing anything while it shows.
.factory('Toast', function($rootScope, $timeout, $ionicPopup, $cordovaToast) {
return {
show: function (message, duration, position) {