I am Working on angularJS2 project and i want to check the response from the RestAPI, Then i'll display the response of restAPI in bootstrap "alert-dismissible". My Code is as follows:
Template Html file(registration.component.html):
<div *ngIf="result && f.submitted" class="alert alert-danger alert-dismissible" role="alert">
<span class="close" data-dismiss="alert">×</span>
{{ result }}
</div>
<h2>Register</h2>
<form name="form" (ngSubmit)="f.form.valid && register()" #f="ngForm" novalidate>
// Form Code
</form>
Typescript file(registration.component.ts):
register() {
this.loading = true;
this.userService.create(this.model)
.subscribe(
data => {
this.result=data.message;
this.loading = false;
},
error => {
this.alertService.error(error);
this.loading = false;
});
}
I am getting the response from the server and my rest API working fine, I am able to display the response in alert-dismissible also. But, problem starts when i close the alert-dismissible and then resubmitting the form , i can see the response in the console but alert-dismissible is not showing.
I know that the problem is in <div *ngIf="result && f.submitted" class="alert alert-danger alert-dismissible" role="alert">
, please guide me how i can check the condition in the NGIF.