Answer the question
In order to leave comments, you need to log in
How to return form field values from modal window?
window template
.modal-header
h5
| {{modalOptions.headerText}}
.modal-body(ng-bind-html='modalOptions.bodyHtml')
.modal-footer
button.btn(
type='button',
ng-click='modalOptions.close()'
)
| {{modalOptions.closeButtonText}}
button.btn.btn-primary(
ng-click='modalOptions.ok(modalOptions.form)'
)
| {{modalOptions.actionButtonText}}
/*global angular*/
(function () {
'use strict';
angular
.module('App')
.service('modalService', ['$uibModal', 'APP_NAME', modalService]);
modalService.$inject = ['$uibModal', 'APP_NAME'];
function modalService($uibModal, APP_NAME) {
var modalDefaults = {
backdrop: true,
keyboard: true,
modalFade: true,
templateUrl: 'js/app/view/ui.templates/modals/modalServiceTemplate.html',
size: 'md'
};
var modalOptions = {
closeButtonText: 'Отмена',
actionButtonText: 'OK',
headerText: APP_NAME,
bodyText: 'Вы уверены?',
form: {}
};
this.showModal = function (customModalDefaults, customModalOptions) {
if (!customModalDefaults){
customModalDefaults = {};
}
customModalDefaults.backdrop = 'static';
return this.show(customModalDefaults, customModalOptions);
};
this.show = function (customModalDefaults, customModalOptions) {
var tempModalDefaults = {};
var tempModalOptions = {};
angular.extend(tempModalDefaults, modalDefaults, customModalDefaults);
angular.extend(tempModalOptions, modalOptions, customModalOptions);
if (!tempModalDefaults.controller) {
tempModalDefaults.controller = ['$scope', '$uibModalInstance', function ($scope, $uibModalInstance) {
$scope.modalOptions = tempModalOptions;
$scope.modalOptions.ok = function (result) {
$uibModalInstance.close(result);
};
$scope.modalOptions.close = function (result) {
$uibModalInstance.dismiss('cancel');
};
}]
tempModalDefaults.controller.$inject = ['$scope', '$uibModalInstance'];
}
return $uibModal.open(tempModalDefaults).result;
};
}
})();
self.submitDelete = function () {
var modalOptions = {
closeButtonText: 'Отмена',
actionButtonText: 'Удалить аккаунт',
//headerText: 'Подтверждение',
bodyText: 'Вы уверены, что хотите удалить аккаунт?',
bodyHtml: $sce.trustAsHtml('<form ng-init="modalOptions.form = {login: "www"}"><input type="text" ng-model="modalOptions.form.login"></form>')
};
modalService.showModal({}, modalOptions).then(function (result) {
console.log(result);
//self.$auth.DeleteAccount();
});
};
Answer the question
In order to leave comments, you need to log in
Solved the problem using the directive.
// window template
// directive name - compile-html
.modal-header
h4
| {{modalOptions.headerText}}
.modal-body(compile-html, ng-bind-html='modalOptions.bodyHtml')
.modal-footer
button.btn(
type='button',
ng-click='modalOptions.close()'
)
| {{modalOptions.closeButtonText}}
button.btn.btn-primary(
ng-click='modalOptions.ok(modalOptions.form)'
)
| {{modalOptions.actionButtonText}}
(function () {
'use strict';
angular
.module('App')
.directive('compileHtml', ['$timeout', '$compile', compileHtml]);
compileHtml.$inject = ['$timeout', '$compile'];
function compileHtml($timeout, $compile) {
var directive = {
restrict:'A',
link: function(scope,elem,attrs){
$timeout(function(){
$compile(elem.contents())(scope);
});
}
};
return directive;
}
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question