I can’t able to scope variable in ionic modal.if am using the variable in ng-modal in the form of data.value means it working fine.but if we use like ng-modal=‘value’ means we can’t access the value in other part of the modal.for example if we set the ng-modal for an input field.we also have a button in the other part of the modal.when we click the button we have to empty the input field. On ng-click set value=null means it doesn’t work.but am using data.value instead of using value for the ng-modal .am set data.value=null on the ng-click it was working fine the field get under properly.
But the thing is if am using data.value for the input field’s ng-modal means it takes a time to perform the action .I really doesn’t what’s wrong in this.i don’t have a clear idea regarding this.please help me to know this issue.
Posting some code would help.
What is the scope of the modal? is it a new scope or the parent (page) scope?
-
Using $scope
$ionicModal.fromTemplateUrl(‘my-modal.html’, {
scope: $scope,
animation: ‘slide-in-up’
}).then(function(modal) {
$scope.modal = modal;
});$scope.openModal = function() {
$scope.modal.show();
};$scope.closeModal = function() {
$scope.modal.hide();
};//Cleanup the modal when we’re done with it!
$scope.$on(’$destroy’, function() {
$scope.modal.remove();
});// Execute action on hide modal
$scope.$on(‘modal.hidden’, function() {
// Execute action
});// Execute action on remove modal
$scope.$on(‘modal.removed’, function() {
// Execute action
});
(refer https://www.tutorialspoint.com/ionic/ionic_js_modal.htm)
2) Using new scope variable
function MyModal($ionicModal, $rootScope) {
var $scope = $rootScope.$new(),
myModalInstanceOptions = {
scope: $scope,
focusFirstInput: true
};
var myModal = {};
return myModal;
}
(refer https://medium.com/@saniyusuf/create-an-isolate-modal-with-ionic-v1-b4cf73f05727)