Вы можете использовать простое ngIf
для достижения этой цели:
generateTicket(){
this._idservice.currentMessage.subscribe(message => this.userId = message)
this._service.createTicketFromRemote(this.ticket, this.userId).subscribe(
data => {
console.log("response recieved");
this.msg = "Ticket Successfully Generated";
this.open_Modal = true; // <------
},
error => {
this.open_Modal = false;
console.log("exception occured");
console.log(error);
// do nothing
}
)
}
в html, добавьте ngIf в основной модальный div:
<div *ngIf="open_Modal" class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class="text-center">Modal Body</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-warning">Print</button>
<button type="submit" class="btn btn-primary" data-dismiss="modal" >Edit</button>
</div>
</div>
</div>
</div>
Вы можете также оберните основной div в ng-container
с помощью ngIf, вместо div, чтобы сделать код более чистым:
<ng-container *ngIf="open_Modal">
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class="text-center">Modal Body</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-warning">Print</button>
<button type="submit" class="btn btn-primary" data-dismiss="modal" >Edit</button>
</div>
</div>
</div>
</div>
</ng-container>