Skip to content

Instantly share code, notes, and snippets.

@oliverm2112
Last active December 16, 2015 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliverm2112/5422351 to your computer and use it in GitHub Desktop.
Save oliverm2112/5422351 to your computer and use it in GitHub Desktop.
DialogService.js
app.factory('dialog', ['$rootScope', '$dialog', function ($rootScope, $dialog) {
$rootScope.$on('alert', function (event, data) {
console.log('alert function:', event.name, data);
/** data should have:
- title, message and optionally, a callback
*/
$dialog.messageBox(data.title, data.message, [
{label : 'OK', result : 'ok'},
{label : 'No way', result : 'nope'}
])
.open()
.then(function (result) {
if (data.callback) {
data.callback(result);
}
}
);
});
$rootScope.$on('confirm', function (event, data) {
console.log('confirm function:', event.name, data);
/** data should have:
- title, message and a callback
*/
$dialog.messageBox(data.title, data.message, [
{label : 'OK', result : 'ok'},
{label : 'Cancel', result : 'cancel'}
])
.open()
.then(function (result) {
data.callback(result);
}
);
});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment