I'm using Dan Wahlin's modal service and got it working, however if I change modal.html to include a partial template in the body, I don't know how to get the model data from the template in the modal's 'ok' click result.
There are two similar questions here and here, but they have the model data inside the modal form, not in a separate template.
My thinking is that I could have a template controller for the result data, but then how would I access it from the modal service and return it to the calling controller?
modal.html:
<div class="inmodal">
<div class="modal-header">
<h4 class="modal-title">{{modalOptions.headerText}}</h4>
</div>
<div class="modal-body">
<div ng-include="modalOptions.bodyTemplateUrl" ></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-ng-click="modalOptions.close()">{{modalOptions.closeButtonText}}</button>
<button class="btn btn-primary" data-ng-click="modalOptions.ok();">{{modalOptions.actionButtonText}}</button>
</div>
controller:
var modalOptions = {
closeButtonText: 'Cancel',
actionButtonText: 'Save',
headerText: 'Modal Title',
bodyText: 'Nicy body.',
bodyTemplateUrl: 'modules/users/views/account/user-password.partial.html'
};
modalService.showModal({}, modalOptions).then(function (result) {
console.log(result.currentPassword);
if (result === 'ok') {
$scope.changeUserPassword();
}
});
user-password.partial.html:
<div > <!-- PasswordController? -->
<form name="passwordForm" class=" form-horizontal" autocomplete="off">
<fieldset>
<div class="form-group">
<input type="password" id="currentPassword" name="currentPassword" class="form-control" data-ng-model="passwordDetails.currentPassword" placeholder="Current password">
</div>
<div class="form-group">
<input type="password" id="newPassword" name="newPassword" class="form-control" data-ng-model="passwordDetails.newPassword" placeholder="New password">
</div>
<div class="form-group">
<input type="password" id="verifyPassword" name="verifyPassword" class="form-control" data-ng-model="passwordDetails.verifyPassword" placeholder="Verify password">
</div>
</fieldset>
</form>
I didn't create a plunker as the links above show the same code except for the bodyTemplateUrl that I've included.