I am attempting to trigger a search function on a button but have a modal popover so I can use angular to format the JSON. The modal functionality works, but to trigger my function I need to have the button type="submit" to trigger the ng-submit. However, when I change the button type, this pulls the JSON but blocks the modal. Is there another way I can trigger the submit? Any suggestions on how to structure this better? Or if there are dependencies I might need? Thank you
JS Code:-
app.controller('homeCtrl', function($rootScope, $stateParams, $http) {
$rootScope.home;
$rootScope.displayCity = false;
$stateParams.city_id;
$rootScope.searchCity = function() {
$rootScope.displayCity = true;
let query = $('#query').val();
$http({
method: 'GET',
url: 'apiUrl',
headers: {
'user-key': $rootScope.key,
},
params: {
'q': query
}
}).then(function(response) {
console.log(response.data);
$rootScope.displayCity = true;
$("#myModal").show()
}).catch(function(response) {
console.log("something went wrong");
});
};
});
HTML Code:-
<div class="container">
<div class="row">
<div class="vh-100 col-12 d-flex flex-column justify-content-center">
<form class="mt-4" ng-submit="searchCity()">
<div class="form-group d-flex">
<input id="query" type="text" placeholder="Search For Your City" class="form-control" />
<!-- Button trigger modal -->
<button type="submit" class="searchbtn btn-danger" data-toggle="modal" data-target="#myModal">
Go
</button>
<!-- Modal -->
<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Select Your City</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>