I've created a small demo to use when i need to open a modal window in Angular. Using a directive as the modal window template.
What im not sure about is the way im passing data/functions to the modal.
The opening controller:
$scope.openModal = function($event){
$scope.items = [1,2,3,4,5];
$scope.modalInstance = $modal.open({
template: '<modalwindow></modalwindow>',
scope:$scope,
test:'akex'
});
$scope.modalInstance.result.then(function (selectedItem) {
console.info(selectedItem);
}, function () {
console.info('Modal dismissed at: ' + new Date());
});
and the modal directive:
angular.module('angModalApp')
.directive('modalwindow', function () {
return {
templateUrl: 'scripts/directives/modalwindow.tmpl.html',
restrict: 'E',
link: function postLink(scope, element, attrs) {
scope.ok = function () {
scope.modalInstance.close(["a","b","c"]);
};
scope.cancel = function () {
scope.modalInstance.dismiss('cancel');
};
}
};
});
What im asking is what you guys think about such use of the modal. Is there a better way of doing it?
Thank you for your time.
The source of the project can be found at: https://github.com/trostik/angular-modal-window-demo