I am very new to the angular world (second day) and trying to work around angular ui. I am trying to build my first modal dialog. The modal dialog is being shown properly but I m not able to use model in that modal dialog. Here is my demo plunker
Here is what I've done so far:
In controller:
appRoot.controller('DemoCtrl', function ($scope, $modal) {
$scope.openDemoModal= function (size) {
var modalInstance = $modal.open({
templateUrl: 'ngPartials/_DemoModal.html',
controller: 'modalCtrl',
size: size,
backdrop: true,
keyboard: true,
modalFade: true
});
};
});
In index.html:
<div ng-controller="DemoCtrl">
<a ng-click="openDemoModal()">Open Modal</a>
</div>
In _DemoModal.html
<div class="modal-header">
<h3 class="modal-title">Test Modal</h3>
</div>
<div class="modal-body">
<input ng-model="testModel"/>
</div>
<div class="modal-footer">
<button ng-click="test()">Test</button>
<button ng-click="cancel()">Cancel</button>
</div>
In controller modalCtrl
appRoot.controller('modalCtrl', function ($scope, $modalInstance) {
$scope.test= function () {
var temp = $scope.testModel;//This shows undefined
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
In modalCtrl $scope.testModel always remains undefined no mater what is in the text box. And if I first set the value of $scope.testModel="some value", it will never change no matter what is in the text box. What exactly wrong I am doing.
Also I want to know, if is it possible to have communication between DemoCtrl and modalCtrl ? For this communication I tried to use concept of events as follows:
In modalCtrl:
$scope.test= function () {
//var temp = $scope.testModel;//This shows undefined
$scope.$emit('someEvent', 'some args');
};
In DemoCtrl:
$scope.$on('someEvent', function (event, args) {
alert('event called');
});
But this is also not working. What exactly I am doing wrong. Is I am creating angular modal in a wrong way? Any help will be great for me. Thanks in advance.