How to close ng-bootstrap Modal in Angular












0














I have two components those are component-A,component-B and in my component-A i have opened ng-bootstrap Model its working fine and problem is when i tapped on close button i want to get reason for dismiss those functionality handled in Component-A



But my close button action is there in component-B how can i handle this scenario can some one help me please.



ComponentA:



public open() {
this.modalService.open(ComponentB, { ariaLabelledBy: 'modal-basic-title', size: 'lg' }).result.
then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}


ComponentB:



 close(){
this.activeModel.close()
}


CoponentB.html



<!--  Model Code Start -->
<div class="modal-header" style="background: deepskyblue; font-size: xx-large;">
<h4 class="modal-title" id="modal-basic-title">Registration & SignIn</h4>
<button type="button" class="close" aria-label="Close" (click)="close()">
<span aria-hidden="true">&times;</span>
</button>
</div>

<!-- Model Body -->
<div class="modal-body">
<!-- Tab Start Code -->
<ngb-tabset>
<ngb-tab>
<ng-template ngbTabTitle><b>Login</b></ng-template>
<ng-template ngbTabContent>
<br>
<form>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">@</span>
</div>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">*</span>
</div>
<input type="password" class="form-control" placeholder="Password" aria-label="Username"
aria-describedby="basic-addon1">
</div>
</div>
<button type="button" style="margin-left: 39%;" class="btn btn-outline-success" (click)="c('Save click')"><b>Login</b></button>
</form>
</ng-template>
</ngb-tab>

<ngb-tab>
<ng-template ngbTabTitle><b>Register</b></ng-template>
<ng-template ngbTabContent>
<br>
<form [formGroup]="registrationForm">
<div class="form-group">
<div class="row">
<div class="col-md-2">
<label for="FormControlUserName" style="color: lightseagreen;font-size: medium;"><b>User Name*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="UserName" placeholder="User Name" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">

<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['UserName'].valid&&registrationForm.controls['UserName'].dirty">
<span *ngIf="registrationForm.controls.UserName.errors.required">User Name is Required.</span>
<span *ngIf="registrationForm.controls.UserName.errors.minlength">User name minimum should be
length
of 3.</span>
<span *ngIf="registrationForm.controls.UserName.errors.maxlength">User name maximum should be
length
of 50.</span>
</span>

</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPassword" style="color: lightseagreen;font-size: medium;"><b>Password*:</b></label>
</div>
<div class="col-md-6">
<input type="password" formControlName="Password" placeholder="Password" class="form-control"
aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Password'].valid&&registrationForm.controls['Password'].dirty">
<span *ngIf="registrationForm.controls.Password.errors.required">Password is Required.</span>
<span *ngIf="registrationForm.controls.Password.errors.minlength">Password minimum should be length
of 3.</span>
<span *ngIf="registrationForm.controls.Password.errors.maxlength">Password maximum should be length
of 50.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlEmail" style="color: lightseagreen;font-size: medium;"><b>Email*:</b></label>
</div>
<div class="col-md-6">
<input type="email" formControlName="Email" placeholder="Email" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Email'].valid&&registrationForm.controls['Email'].dirty">
<span *ngIf="registrationForm.controls.Email.errors.required">Email is Required.</span>
<span *ngIf="registrationForm.controls.Email.errors.email">Email is not in correct pattern.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlRole" style="color: lightseagreen;font-size: medium;"><b>Role*:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Role" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Role" id="exampleFormControlSelect2">
<option [ngValue]="undefined">Select Role</option>
<option>Customer</option>
<option>Sellers</option>
<option>Tech Support</option>
<option>CSE</option>
</select>
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Role'].valid&&registrationForm.controls['Role'].dirty&&registrationForm.controls['Role'].touched">
<span *ngIf="registrationForm.controls.Role.errors.required">Role is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPhone" style="color: lightseagreen;font-size: medium;"><b>Phone No*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="Phone" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Phone'].valid&&registrationForm.controls['Phone'].dirty">
<span *ngIf="registrationForm.controls.Phone.errors.required">Phone is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlGender" style="color: lightseagreen;font-size: medium;"><b>Gender:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Gender" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Gender" id="exampleFormControlSelect1">
<option>Select Gender</option>
<option>Male</option>
<option>Female</option>
<option>Not prefer to dislose</option>
</select>
</div>
<div class="col-md-4">

</div>
</div>
</div>
<button type="button" style="margin-left: 39%;" [disabled]="!registrationForm.valid" class="btn btn-outline-success"
(click)="OnRegister(registrationForm.value)"><b>Register</b></button>
</form>

</ng-template>
</ngb-tab>
</ngb-tabset>
<!-- Tab End Code -->
</div>

<!-- Model Footer -->
<div class="modal-footer">
<p *ngFor="let alert of alerts">
<ngb-alert style="width: 758px;" [type]="alert.type" (close)="staticAlertClosed = true">{{ alert.message }}</ngb-alert>
</p>
</div>









share|improve this question






















  • you want to close all model when you click cancel?
    – Chellappan
    Nov 13 '18 at 6:35










  • There are two ways, one with @Input directive and the other is with the this.modalService.componentInstance . 2nd one will gives you a reference Component B's instance where you can easily get access to its variables.
    – Farooq Khan
    Nov 13 '18 at 6:43










  • @chellapan No actually when i tapped on close button i want display reason
    – AbhiRam
    Nov 13 '18 at 6:43












  • @FarooqKhan can you please explain with some code
    – AbhiRam
    Nov 13 '18 at 6:44










  • wait, you are not passing any reason in your code. here this.activeModal.close(). It should be this.activeModal.dismissAll('Reason').
    – Farooq Khan
    Nov 13 '18 at 6:51
















0














I have two components those are component-A,component-B and in my component-A i have opened ng-bootstrap Model its working fine and problem is when i tapped on close button i want to get reason for dismiss those functionality handled in Component-A



But my close button action is there in component-B how can i handle this scenario can some one help me please.



ComponentA:



public open() {
this.modalService.open(ComponentB, { ariaLabelledBy: 'modal-basic-title', size: 'lg' }).result.
then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}


ComponentB:



 close(){
this.activeModel.close()
}


CoponentB.html



<!--  Model Code Start -->
<div class="modal-header" style="background: deepskyblue; font-size: xx-large;">
<h4 class="modal-title" id="modal-basic-title">Registration & SignIn</h4>
<button type="button" class="close" aria-label="Close" (click)="close()">
<span aria-hidden="true">&times;</span>
</button>
</div>

<!-- Model Body -->
<div class="modal-body">
<!-- Tab Start Code -->
<ngb-tabset>
<ngb-tab>
<ng-template ngbTabTitle><b>Login</b></ng-template>
<ng-template ngbTabContent>
<br>
<form>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">@</span>
</div>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">*</span>
</div>
<input type="password" class="form-control" placeholder="Password" aria-label="Username"
aria-describedby="basic-addon1">
</div>
</div>
<button type="button" style="margin-left: 39%;" class="btn btn-outline-success" (click)="c('Save click')"><b>Login</b></button>
</form>
</ng-template>
</ngb-tab>

<ngb-tab>
<ng-template ngbTabTitle><b>Register</b></ng-template>
<ng-template ngbTabContent>
<br>
<form [formGroup]="registrationForm">
<div class="form-group">
<div class="row">
<div class="col-md-2">
<label for="FormControlUserName" style="color: lightseagreen;font-size: medium;"><b>User Name*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="UserName" placeholder="User Name" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">

<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['UserName'].valid&&registrationForm.controls['UserName'].dirty">
<span *ngIf="registrationForm.controls.UserName.errors.required">User Name is Required.</span>
<span *ngIf="registrationForm.controls.UserName.errors.minlength">User name minimum should be
length
of 3.</span>
<span *ngIf="registrationForm.controls.UserName.errors.maxlength">User name maximum should be
length
of 50.</span>
</span>

</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPassword" style="color: lightseagreen;font-size: medium;"><b>Password*:</b></label>
</div>
<div class="col-md-6">
<input type="password" formControlName="Password" placeholder="Password" class="form-control"
aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Password'].valid&&registrationForm.controls['Password'].dirty">
<span *ngIf="registrationForm.controls.Password.errors.required">Password is Required.</span>
<span *ngIf="registrationForm.controls.Password.errors.minlength">Password minimum should be length
of 3.</span>
<span *ngIf="registrationForm.controls.Password.errors.maxlength">Password maximum should be length
of 50.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlEmail" style="color: lightseagreen;font-size: medium;"><b>Email*:</b></label>
</div>
<div class="col-md-6">
<input type="email" formControlName="Email" placeholder="Email" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Email'].valid&&registrationForm.controls['Email'].dirty">
<span *ngIf="registrationForm.controls.Email.errors.required">Email is Required.</span>
<span *ngIf="registrationForm.controls.Email.errors.email">Email is not in correct pattern.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlRole" style="color: lightseagreen;font-size: medium;"><b>Role*:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Role" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Role" id="exampleFormControlSelect2">
<option [ngValue]="undefined">Select Role</option>
<option>Customer</option>
<option>Sellers</option>
<option>Tech Support</option>
<option>CSE</option>
</select>
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Role'].valid&&registrationForm.controls['Role'].dirty&&registrationForm.controls['Role'].touched">
<span *ngIf="registrationForm.controls.Role.errors.required">Role is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPhone" style="color: lightseagreen;font-size: medium;"><b>Phone No*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="Phone" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Phone'].valid&&registrationForm.controls['Phone'].dirty">
<span *ngIf="registrationForm.controls.Phone.errors.required">Phone is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlGender" style="color: lightseagreen;font-size: medium;"><b>Gender:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Gender" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Gender" id="exampleFormControlSelect1">
<option>Select Gender</option>
<option>Male</option>
<option>Female</option>
<option>Not prefer to dislose</option>
</select>
</div>
<div class="col-md-4">

</div>
</div>
</div>
<button type="button" style="margin-left: 39%;" [disabled]="!registrationForm.valid" class="btn btn-outline-success"
(click)="OnRegister(registrationForm.value)"><b>Register</b></button>
</form>

</ng-template>
</ngb-tab>
</ngb-tabset>
<!-- Tab End Code -->
</div>

<!-- Model Footer -->
<div class="modal-footer">
<p *ngFor="let alert of alerts">
<ngb-alert style="width: 758px;" [type]="alert.type" (close)="staticAlertClosed = true">{{ alert.message }}</ngb-alert>
</p>
</div>









share|improve this question






















  • you want to close all model when you click cancel?
    – Chellappan
    Nov 13 '18 at 6:35










  • There are two ways, one with @Input directive and the other is with the this.modalService.componentInstance . 2nd one will gives you a reference Component B's instance where you can easily get access to its variables.
    – Farooq Khan
    Nov 13 '18 at 6:43










  • @chellapan No actually when i tapped on close button i want display reason
    – AbhiRam
    Nov 13 '18 at 6:43












  • @FarooqKhan can you please explain with some code
    – AbhiRam
    Nov 13 '18 at 6:44










  • wait, you are not passing any reason in your code. here this.activeModal.close(). It should be this.activeModal.dismissAll('Reason').
    – Farooq Khan
    Nov 13 '18 at 6:51














0












0








0







I have two components those are component-A,component-B and in my component-A i have opened ng-bootstrap Model its working fine and problem is when i tapped on close button i want to get reason for dismiss those functionality handled in Component-A



But my close button action is there in component-B how can i handle this scenario can some one help me please.



ComponentA:



public open() {
this.modalService.open(ComponentB, { ariaLabelledBy: 'modal-basic-title', size: 'lg' }).result.
then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}


ComponentB:



 close(){
this.activeModel.close()
}


CoponentB.html



<!--  Model Code Start -->
<div class="modal-header" style="background: deepskyblue; font-size: xx-large;">
<h4 class="modal-title" id="modal-basic-title">Registration & SignIn</h4>
<button type="button" class="close" aria-label="Close" (click)="close()">
<span aria-hidden="true">&times;</span>
</button>
</div>

<!-- Model Body -->
<div class="modal-body">
<!-- Tab Start Code -->
<ngb-tabset>
<ngb-tab>
<ng-template ngbTabTitle><b>Login</b></ng-template>
<ng-template ngbTabContent>
<br>
<form>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">@</span>
</div>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">*</span>
</div>
<input type="password" class="form-control" placeholder="Password" aria-label="Username"
aria-describedby="basic-addon1">
</div>
</div>
<button type="button" style="margin-left: 39%;" class="btn btn-outline-success" (click)="c('Save click')"><b>Login</b></button>
</form>
</ng-template>
</ngb-tab>

<ngb-tab>
<ng-template ngbTabTitle><b>Register</b></ng-template>
<ng-template ngbTabContent>
<br>
<form [formGroup]="registrationForm">
<div class="form-group">
<div class="row">
<div class="col-md-2">
<label for="FormControlUserName" style="color: lightseagreen;font-size: medium;"><b>User Name*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="UserName" placeholder="User Name" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">

<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['UserName'].valid&&registrationForm.controls['UserName'].dirty">
<span *ngIf="registrationForm.controls.UserName.errors.required">User Name is Required.</span>
<span *ngIf="registrationForm.controls.UserName.errors.minlength">User name minimum should be
length
of 3.</span>
<span *ngIf="registrationForm.controls.UserName.errors.maxlength">User name maximum should be
length
of 50.</span>
</span>

</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPassword" style="color: lightseagreen;font-size: medium;"><b>Password*:</b></label>
</div>
<div class="col-md-6">
<input type="password" formControlName="Password" placeholder="Password" class="form-control"
aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Password'].valid&&registrationForm.controls['Password'].dirty">
<span *ngIf="registrationForm.controls.Password.errors.required">Password is Required.</span>
<span *ngIf="registrationForm.controls.Password.errors.minlength">Password minimum should be length
of 3.</span>
<span *ngIf="registrationForm.controls.Password.errors.maxlength">Password maximum should be length
of 50.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlEmail" style="color: lightseagreen;font-size: medium;"><b>Email*:</b></label>
</div>
<div class="col-md-6">
<input type="email" formControlName="Email" placeholder="Email" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Email'].valid&&registrationForm.controls['Email'].dirty">
<span *ngIf="registrationForm.controls.Email.errors.required">Email is Required.</span>
<span *ngIf="registrationForm.controls.Email.errors.email">Email is not in correct pattern.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlRole" style="color: lightseagreen;font-size: medium;"><b>Role*:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Role" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Role" id="exampleFormControlSelect2">
<option [ngValue]="undefined">Select Role</option>
<option>Customer</option>
<option>Sellers</option>
<option>Tech Support</option>
<option>CSE</option>
</select>
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Role'].valid&&registrationForm.controls['Role'].dirty&&registrationForm.controls['Role'].touched">
<span *ngIf="registrationForm.controls.Role.errors.required">Role is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPhone" style="color: lightseagreen;font-size: medium;"><b>Phone No*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="Phone" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Phone'].valid&&registrationForm.controls['Phone'].dirty">
<span *ngIf="registrationForm.controls.Phone.errors.required">Phone is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlGender" style="color: lightseagreen;font-size: medium;"><b>Gender:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Gender" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Gender" id="exampleFormControlSelect1">
<option>Select Gender</option>
<option>Male</option>
<option>Female</option>
<option>Not prefer to dislose</option>
</select>
</div>
<div class="col-md-4">

</div>
</div>
</div>
<button type="button" style="margin-left: 39%;" [disabled]="!registrationForm.valid" class="btn btn-outline-success"
(click)="OnRegister(registrationForm.value)"><b>Register</b></button>
</form>

</ng-template>
</ngb-tab>
</ngb-tabset>
<!-- Tab End Code -->
</div>

<!-- Model Footer -->
<div class="modal-footer">
<p *ngFor="let alert of alerts">
<ngb-alert style="width: 758px;" [type]="alert.type" (close)="staticAlertClosed = true">{{ alert.message }}</ngb-alert>
</p>
</div>









share|improve this question













I have two components those are component-A,component-B and in my component-A i have opened ng-bootstrap Model its working fine and problem is when i tapped on close button i want to get reason for dismiss those functionality handled in Component-A



But my close button action is there in component-B how can i handle this scenario can some one help me please.



ComponentA:



public open() {
this.modalService.open(ComponentB, { ariaLabelledBy: 'modal-basic-title', size: 'lg' }).result.
then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}

private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}


ComponentB:



 close(){
this.activeModel.close()
}


CoponentB.html



<!--  Model Code Start -->
<div class="modal-header" style="background: deepskyblue; font-size: xx-large;">
<h4 class="modal-title" id="modal-basic-title">Registration & SignIn</h4>
<button type="button" class="close" aria-label="Close" (click)="close()">
<span aria-hidden="true">&times;</span>
</button>
</div>

<!-- Model Body -->
<div class="modal-body">
<!-- Tab Start Code -->
<ngb-tabset>
<ngb-tab>
<ng-template ngbTabTitle><b>Login</b></ng-template>
<ng-template ngbTabContent>
<br>
<form>
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">@</span>
</div>
<input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">*</span>
</div>
<input type="password" class="form-control" placeholder="Password" aria-label="Username"
aria-describedby="basic-addon1">
</div>
</div>
<button type="button" style="margin-left: 39%;" class="btn btn-outline-success" (click)="c('Save click')"><b>Login</b></button>
</form>
</ng-template>
</ngb-tab>

<ngb-tab>
<ng-template ngbTabTitle><b>Register</b></ng-template>
<ng-template ngbTabContent>
<br>
<form [formGroup]="registrationForm">
<div class="form-group">
<div class="row">
<div class="col-md-2">
<label for="FormControlUserName" style="color: lightseagreen;font-size: medium;"><b>User Name*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="UserName" placeholder="User Name" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">

<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['UserName'].valid&&registrationForm.controls['UserName'].dirty">
<span *ngIf="registrationForm.controls.UserName.errors.required">User Name is Required.</span>
<span *ngIf="registrationForm.controls.UserName.errors.minlength">User name minimum should be
length
of 3.</span>
<span *ngIf="registrationForm.controls.UserName.errors.maxlength">User name maximum should be
length
of 50.</span>
</span>

</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPassword" style="color: lightseagreen;font-size: medium;"><b>Password*:</b></label>
</div>
<div class="col-md-6">
<input type="password" formControlName="Password" placeholder="Password" class="form-control"
aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Password'].valid&&registrationForm.controls['Password'].dirty">
<span *ngIf="registrationForm.controls.Password.errors.required">Password is Required.</span>
<span *ngIf="registrationForm.controls.Password.errors.minlength">Password minimum should be length
of 3.</span>
<span *ngIf="registrationForm.controls.Password.errors.maxlength">Password maximum should be length
of 50.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlEmail" style="color: lightseagreen;font-size: medium;"><b>Email*:</b></label>
</div>
<div class="col-md-6">
<input type="email" formControlName="Email" placeholder="Email" class="form-control" aria-label="Default"
aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Email'].valid&&registrationForm.controls['Email'].dirty">
<span *ngIf="registrationForm.controls.Email.errors.required">Email is Required.</span>
<span *ngIf="registrationForm.controls.Email.errors.email">Email is not in correct pattern.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlRole" style="color: lightseagreen;font-size: medium;"><b>Role*:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Role" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Role" id="exampleFormControlSelect2">
<option [ngValue]="undefined">Select Role</option>
<option>Customer</option>
<option>Sellers</option>
<option>Tech Support</option>
<option>CSE</option>
</select>
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Role'].valid&&registrationForm.controls['Role'].dirty&&registrationForm.controls['Role'].touched">
<span *ngIf="registrationForm.controls.Role.errors.required">Role is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlPhone" style="color: lightseagreen;font-size: medium;"><b>Phone No*:</b></label>
</div>
<div class="col-md-6">
<input type="text" formControlName="Phone" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default">
</div>
<div class="col-md-4">
<span style="font-weight: bold;color: red;" *ngIf="!registrationForm.controls['Phone'].valid&&registrationForm.controls['Phone'].dirty">
<span *ngIf="registrationForm.controls.Phone.errors.required">Phone is Required.</span>
</span>
</div>
</div>
<br>
<div class="row">
<div class="col-md-2">
<label for="FormControlGender" style="color: lightseagreen;font-size: medium;"><b>Gender:</b></label>
</div>
<div class="col-md-6">
<!-- <input type="text" formControlName="Gender" class="form-control" aria-label="Default" aria-describedby="inputGroup-sizing-default"> -->
<select class="form-control" formControlName="Gender" id="exampleFormControlSelect1">
<option>Select Gender</option>
<option>Male</option>
<option>Female</option>
<option>Not prefer to dislose</option>
</select>
</div>
<div class="col-md-4">

</div>
</div>
</div>
<button type="button" style="margin-left: 39%;" [disabled]="!registrationForm.valid" class="btn btn-outline-success"
(click)="OnRegister(registrationForm.value)"><b>Register</b></button>
</form>

</ng-template>
</ngb-tab>
</ngb-tabset>
<!-- Tab End Code -->
</div>

<!-- Model Footer -->
<div class="modal-footer">
<p *ngFor="let alert of alerts">
<ngb-alert style="width: 758px;" [type]="alert.type" (close)="staticAlertClosed = true">{{ alert.message }}</ngb-alert>
</p>
</div>






angular ng-bootstrap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 6:25









AbhiRam

45211139




45211139












  • you want to close all model when you click cancel?
    – Chellappan
    Nov 13 '18 at 6:35










  • There are two ways, one with @Input directive and the other is with the this.modalService.componentInstance . 2nd one will gives you a reference Component B's instance where you can easily get access to its variables.
    – Farooq Khan
    Nov 13 '18 at 6:43










  • @chellapan No actually when i tapped on close button i want display reason
    – AbhiRam
    Nov 13 '18 at 6:43












  • @FarooqKhan can you please explain with some code
    – AbhiRam
    Nov 13 '18 at 6:44










  • wait, you are not passing any reason in your code. here this.activeModal.close(). It should be this.activeModal.dismissAll('Reason').
    – Farooq Khan
    Nov 13 '18 at 6:51


















  • you want to close all model when you click cancel?
    – Chellappan
    Nov 13 '18 at 6:35










  • There are two ways, one with @Input directive and the other is with the this.modalService.componentInstance . 2nd one will gives you a reference Component B's instance where you can easily get access to its variables.
    – Farooq Khan
    Nov 13 '18 at 6:43










  • @chellapan No actually when i tapped on close button i want display reason
    – AbhiRam
    Nov 13 '18 at 6:43












  • @FarooqKhan can you please explain with some code
    – AbhiRam
    Nov 13 '18 at 6:44










  • wait, you are not passing any reason in your code. here this.activeModal.close(). It should be this.activeModal.dismissAll('Reason').
    – Farooq Khan
    Nov 13 '18 at 6:51
















you want to close all model when you click cancel?
– Chellappan
Nov 13 '18 at 6:35




you want to close all model when you click cancel?
– Chellappan
Nov 13 '18 at 6:35












There are two ways, one with @Input directive and the other is with the this.modalService.componentInstance . 2nd one will gives you a reference Component B's instance where you can easily get access to its variables.
– Farooq Khan
Nov 13 '18 at 6:43




There are two ways, one with @Input directive and the other is with the this.modalService.componentInstance . 2nd one will gives you a reference Component B's instance where you can easily get access to its variables.
– Farooq Khan
Nov 13 '18 at 6:43












@chellapan No actually when i tapped on close button i want display reason
– AbhiRam
Nov 13 '18 at 6:43






@chellapan No actually when i tapped on close button i want display reason
– AbhiRam
Nov 13 '18 at 6:43














@FarooqKhan can you please explain with some code
– AbhiRam
Nov 13 '18 at 6:44




@FarooqKhan can you please explain with some code
– AbhiRam
Nov 13 '18 at 6:44












wait, you are not passing any reason in your code. here this.activeModal.close(). It should be this.activeModal.dismissAll('Reason').
– Farooq Khan
Nov 13 '18 at 6:51




wait, you are not passing any reason in your code. here this.activeModal.close(). It should be this.activeModal.dismissAll('Reason').
– Farooq Khan
Nov 13 '18 at 6:51












1 Answer
1






active

oldest

votes


















0














Logically your component B should be like this



class ComponentB {
constructor(private activeModal: NgbModal){ }

/* close modal instance */
close(){ this.activeModal.dismissAll('Reason');} // the component you pass in modalService as container should have NgbModal in constructor
}


Component A

let instance = modalService.show(ComponentB, 'Template-Path-to-HTML');
instance.result.then(() => { /* success */}, (reason) => { /* Reason should be here :-)*/})





share|improve this answer





















  • .activeModal.dismissAll showing error
    – AbhiRam
    Nov 13 '18 at 7:16










  • NgbModal does not have function dismissAll
    – AbhiRam
    Nov 13 '18 at 7:17










  • NgbModal does have the function. Please share your complete code let me check if there is a syntax error. For reference check this source [github.com/ng-bootstrap/ng-bootstrap/blob/master/src/modal/…
    – Farooq Khan
    Nov 13 '18 at 7:20












  • ok i will send my source code please wait
    – AbhiRam
    Nov 13 '18 at 7:21










  • please send me your personal email-id
    – AbhiRam
    Nov 13 '18 at 7:22











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275012%2fhow-to-close-ng-bootstrap-modal-in-angular%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Logically your component B should be like this



class ComponentB {
constructor(private activeModal: NgbModal){ }

/* close modal instance */
close(){ this.activeModal.dismissAll('Reason');} // the component you pass in modalService as container should have NgbModal in constructor
}


Component A

let instance = modalService.show(ComponentB, 'Template-Path-to-HTML');
instance.result.then(() => { /* success */}, (reason) => { /* Reason should be here :-)*/})





share|improve this answer





















  • .activeModal.dismissAll showing error
    – AbhiRam
    Nov 13 '18 at 7:16










  • NgbModal does not have function dismissAll
    – AbhiRam
    Nov 13 '18 at 7:17










  • NgbModal does have the function. Please share your complete code let me check if there is a syntax error. For reference check this source [github.com/ng-bootstrap/ng-bootstrap/blob/master/src/modal/…
    – Farooq Khan
    Nov 13 '18 at 7:20












  • ok i will send my source code please wait
    – AbhiRam
    Nov 13 '18 at 7:21










  • please send me your personal email-id
    – AbhiRam
    Nov 13 '18 at 7:22
















0














Logically your component B should be like this



class ComponentB {
constructor(private activeModal: NgbModal){ }

/* close modal instance */
close(){ this.activeModal.dismissAll('Reason');} // the component you pass in modalService as container should have NgbModal in constructor
}


Component A

let instance = modalService.show(ComponentB, 'Template-Path-to-HTML');
instance.result.then(() => { /* success */}, (reason) => { /* Reason should be here :-)*/})





share|improve this answer





















  • .activeModal.dismissAll showing error
    – AbhiRam
    Nov 13 '18 at 7:16










  • NgbModal does not have function dismissAll
    – AbhiRam
    Nov 13 '18 at 7:17










  • NgbModal does have the function. Please share your complete code let me check if there is a syntax error. For reference check this source [github.com/ng-bootstrap/ng-bootstrap/blob/master/src/modal/…
    – Farooq Khan
    Nov 13 '18 at 7:20












  • ok i will send my source code please wait
    – AbhiRam
    Nov 13 '18 at 7:21










  • please send me your personal email-id
    – AbhiRam
    Nov 13 '18 at 7:22














0












0








0






Logically your component B should be like this



class ComponentB {
constructor(private activeModal: NgbModal){ }

/* close modal instance */
close(){ this.activeModal.dismissAll('Reason');} // the component you pass in modalService as container should have NgbModal in constructor
}


Component A

let instance = modalService.show(ComponentB, 'Template-Path-to-HTML');
instance.result.then(() => { /* success */}, (reason) => { /* Reason should be here :-)*/})





share|improve this answer












Logically your component B should be like this



class ComponentB {
constructor(private activeModal: NgbModal){ }

/* close modal instance */
close(){ this.activeModal.dismissAll('Reason');} // the component you pass in modalService as container should have NgbModal in constructor
}


Component A

let instance = modalService.show(ComponentB, 'Template-Path-to-HTML');
instance.result.then(() => { /* success */}, (reason) => { /* Reason should be here :-)*/})






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 7:05









Farooq Khan

1,46911429




1,46911429












  • .activeModal.dismissAll showing error
    – AbhiRam
    Nov 13 '18 at 7:16










  • NgbModal does not have function dismissAll
    – AbhiRam
    Nov 13 '18 at 7:17










  • NgbModal does have the function. Please share your complete code let me check if there is a syntax error. For reference check this source [github.com/ng-bootstrap/ng-bootstrap/blob/master/src/modal/…
    – Farooq Khan
    Nov 13 '18 at 7:20












  • ok i will send my source code please wait
    – AbhiRam
    Nov 13 '18 at 7:21










  • please send me your personal email-id
    – AbhiRam
    Nov 13 '18 at 7:22


















  • .activeModal.dismissAll showing error
    – AbhiRam
    Nov 13 '18 at 7:16










  • NgbModal does not have function dismissAll
    – AbhiRam
    Nov 13 '18 at 7:17










  • NgbModal does have the function. Please share your complete code let me check if there is a syntax error. For reference check this source [github.com/ng-bootstrap/ng-bootstrap/blob/master/src/modal/…
    – Farooq Khan
    Nov 13 '18 at 7:20












  • ok i will send my source code please wait
    – AbhiRam
    Nov 13 '18 at 7:21










  • please send me your personal email-id
    – AbhiRam
    Nov 13 '18 at 7:22
















.activeModal.dismissAll showing error
– AbhiRam
Nov 13 '18 at 7:16




.activeModal.dismissAll showing error
– AbhiRam
Nov 13 '18 at 7:16












NgbModal does not have function dismissAll
– AbhiRam
Nov 13 '18 at 7:17




NgbModal does not have function dismissAll
– AbhiRam
Nov 13 '18 at 7:17












NgbModal does have the function. Please share your complete code let me check if there is a syntax error. For reference check this source [github.com/ng-bootstrap/ng-bootstrap/blob/master/src/modal/…
– Farooq Khan
Nov 13 '18 at 7:20






NgbModal does have the function. Please share your complete code let me check if there is a syntax error. For reference check this source [github.com/ng-bootstrap/ng-bootstrap/blob/master/src/modal/…
– Farooq Khan
Nov 13 '18 at 7:20














ok i will send my source code please wait
– AbhiRam
Nov 13 '18 at 7:21




ok i will send my source code please wait
– AbhiRam
Nov 13 '18 at 7:21












please send me your personal email-id
– AbhiRam
Nov 13 '18 at 7:22




please send me your personal email-id
– AbhiRam
Nov 13 '18 at 7:22


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275012%2fhow-to-close-ng-bootstrap-modal-in-angular%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python