I am using controllerAs syntax and opening angular-ui modal dialog from it with variable passed to modal controller using "resolve". After opening, I am executing ajax "request", and "updating" variable passed to modal controller. However in modal controller this change is not reflected. Code snippet:
angular.module('main')
.controller('mainCtrl', ['$modal', function($modal){
vm = this;
vm.paymentMessage = 'We are processing you request. Wait a moment.';
vm.showModal();
testService.TestAjax().then(function(response){
vm.paymentMessage = response.data.message;
});
vm.showModal = function() {
var modalConfig = {
controller: 'ModalProcessingCtrl as modalProcessingCtrl',
templateUrl: 'template/processingModal.html',
size: 'lg',
resolve: {
paymentMessage: function () {
return vm.paymentMessage;
}
}
};
$modal.open(modalConfig).result;
};
}])
.controller('ModalProcessingCtrl', ['$modalInstance','paymentMessage', function($modalInstance, paymentMessage){
self = this;
self.paymentMessage = paymentMessage;
self.cancel = function () {
$modalInstance.dismiss('cancel');
};
}])
and the tamplate is like this:
<script type="text/ng-template" id="template/processingModal.html">
<div class="modal-header">
<button type="button" class="close" ng-click="modalProcessingCtrl.cancel()"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="id_card_processing_label">Processing</h4>
</div>
<div class="modal-body">
<div>
<p>{{ modalProcessingCtrl.paymentMessage }}</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="modalProcessingCtrl.cancel()">Close</button>
</div>
</script>
I can see message initially set, but not updated message after ajax request call finished. Is there any way to reflect changes for paymentMessage from mainCtrl in modalProcessingCtrl and show it in modal dialog? Thanks