I am facing an issue with my modal pop up form in Angular.js. I am unable to retrieve the form data using ng-model. Below is the code snippet:
<modal title="Owner Information" visible="showModal">
<form class="ng-pristine ng-valid" id="frmsignup" name="frmsignup" autocomplete="off">
<div class="input-group bmargindiv1 col-lg-4 col-md-4 col-sm-4 col-xs-12 plr-15">
<span class="input-group-addon ndrftextwidth text-left">Status:</span>
<select class="form-control" name="status" id="status" ng-model="status" required="required">
<option value="">Select Status</option>
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
</div>
<div class="input-group bmargindiv1 col-lg-4 col-md-4 col-sm-4 col-xs-12 plr-15">
<span class="input-group-addon ndrftextwidth text-left">Comment:</span>
<textarea rows="5" cols="50" class="form-control" id="comment" name="comment" ng-model="comment" required="required">
</textarea>
</div>
<input type="button" class="btn btn-success" ng-click="updateOwnerData();" id="addProfileData" value="Save" />
</form>
</modal>
Here is a glimpse of my modal pop up:
var dept=angular.module('cab');
dept.controller('ownerviewController',function($scope,$http,$timeout,$state,Upload,$window,DataService){
$scope.updateOwnerData=function(){
console.log('data',$scope.status,$scope.comment);
}
})
dept.directive('modal', function () {
return {
template: '<div class="modal fade">' +
'<div class="modal-dialog modal-lg">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
'<h4 class="modal-title">{{ title }}</h4>' +
'</div>' +
'<div class="modal-body" ng-transclude></div>' +
'</div>' +
'</div>' +
'</div>',
restrict: 'E',
transclude: true,
replace:true,
scope:true,
link: function postLink(scope, element, attrs) {
scope.title = attrs.title;
scope.$watch(attrs.visible, function(value){
if(value == true)
$(element).modal('show');
else
$(element).modal('hide');
});
$(element).on('shown.bs.modal', function(){
scope.$apply(function(){
scope.$parent[attrs.visible] = true;
});
});
$(element).on('hidden.bs.modal', function(){
scope.$apply(function(){
scope.$parent[attrs.visible] = false;
});
});
}
};
});
The above script part highlights my problem - I cannot fetch values through $scope from the popup window. My goal is to capture these values via Angular.js Scope.