I want user click the Submit button and the modal close automatically.
If I add data-dismiss="modal"
in the Submit <button>
, it won't run submitComments()
.
I tried to do something like $('#myModal').modal('hide');
, but not succeed.
So how can I close a modal in Angular 2? Thanks
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Open Modal</button>
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<form (ngSubmit)="submitComments()">
<div class="form-group row">
<label class="form-control-label col-sm-2">Comments:</label>
<div class="col-sm-10">
<textarea class="form-control" rows="3"></textarea>
</div>
</div>
<div class="form-group row">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
.
submitComments() {
// I want to do something like $('#myModal').modal('hide'); here.
}