I feel like this should work, but it's not. I want to be able to pass the controller that is opening the modal so I can use its submit function etc. I am using the controllerAs pattern (so not using $scope).
var _this = this;
this.openModal = function(modalId,dataIn){
this.modalInstance = $modal.open({
templateUrl: modalId,
controller: 'ModalCtrl',
controllerAs: 'modal',
resolve: {
modalObject: function(){
return dataIn;
},
title: function(){
return 'Training Info';
},
parent: function(){
return _this
}
}
});
_this.modalInstance.result.then(function (data) {
$log.log('submitting data for '+_this.doctorId);
experienceFactory.submitTraining(data).then(function(){
loadExperience();
},function(error){
console.log(error);
});
}, function () {
//something on close
$log.info('Modal dismissed at: ' + new Date());
});
};
this.something = function(){
$log.warn('omg it workt?');
};
That is opened up with a simple aCtrl.openModal('a-modal',aCtrl.data) however for some reason I can't access the parent controller
<script type="text/ng-template" id="a-modal">
<div class="modal-header">
<h3 class="modal-title">{{modal.title}}</h3>
</div>
<div class="modal-body">
<button ng-click="parent.something()">Something</button>
</div>
</script>
The button does nothing, but should be printing the warnings. Any ideas appreciated. Thanks.