Last active
August 29, 2015 14:28
-
-
Save rhutchison/9019bcb02ab07db26b66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular | |
.module('core') | |
.controller('ModalController', ModalController); | |
ModalController.$inject = ['$modalInstance', 'model', 'attrs']; | |
function ModalController($modalInstance, model, attrs) { | |
var vm = this; | |
vm.cancel = cancel; | |
vm.done = done; | |
vm.model = model; | |
function cancel() { | |
$modalInstance.dismiss('cancel'); | |
} | |
function done() { | |
$modalInstance.save(vm.model); | |
} | |
} | |
angular | |
.module('core') | |
.controller('Controller', Controller); | |
Controller.$inject = ['$scope', 'model']; | |
function Controller($scope, model) { | |
var vm = this; | |
vm.model = model; | |
vm.openModal = openModal; | |
var modalOptions = { | |
templateUrl: 'modules/core/views/modal.html', | |
controller: 'ModalController', | |
controllerAs: 'vm' | |
}; | |
function openModal(model) { | |
modalFactory | |
.open(model, modalOptions, { | |
foo: 'bar' | |
}) | |
.result | |
.then(successCallback); | |
} | |
function successCallback(res) { | |
console.log('success', res); | |
} | |
} | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
angular | |
.module('core') | |
.factory('modalFactory', ModalFactory); | |
ModalFactory.$inject = ['$modal']; | |
function ModalFactory($modal) { | |
return { | |
open: open | |
} | |
function open(model, options, attrs) { | |
var defaults = { | |
backdrop: 'static', | |
resolve: { | |
model: function () { | |
return angular.copy(model); | |
}, | |
attrs: function () { | |
return attrs; | |
} | |
} | |
}; | |
var promise = $modal.open(angular.extend({}, defaults, options)) | |
promise.save = function (result) { | |
angular.copy(result, model); | |
return promise.close(model); | |
} | |
return promise; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment