Hi All I am currently developing an app that requires to display questions one by one and then post the answers from the input field in the post request. so do so I have created a form where I have taken questions in div and showing and hiding one after another on click of next button but when I click on create project button the answer for the last question is only fetched and send in the post.
here is my html
<form #projectForm="ngForm" novalidate (ngSubmit)="onCreateProject(projectForm)">
<div class="form-group row mt-3 justify-content-center" *ngIf="isShow1">
<label for="projectname" class="col-sm-3 col-md-2 col-form-label">Project name</label>
<div class="col-sm-6 col-md-5">
<input type="text" #projectname="ngModel" [class.is-invalid]="projectname.invalid && projectname.touched"
class="form-control" name="projectname" placeholder="Enter projectname"
[(ngModel)]="project.projectname" required>
<span class="text-danger" [class.d-none]="projectname.valid || projectname.untouched">projectname is required</span>
</div>
<label class="btn btn-primary" (click)="onNext1(pr)">Next</label>
</div>
<div class="form-group row mt-3 justify-content-center" *ngIf="isShow2">
<label for="projectdescription" class="col-sm-3 col-md-2 col-form-label">project description</label>
<div class="col-sm-6 col-md-5">
<input type="text" #projectdescription="ngModel" [class.is-invalid]="projectdescription.invalid && projectdescription.touched"
class="form-control" name="projectdescription" placeholder="Enter projectdescription"
[(ngModel)]="project.projectdescription" required>
<span class="text-danger" [class.d-none]="projectdescription.valid || projectdescription.untouched">projectdescription is required</span>
</div>
<!-- <button class="btn btn-primary" (click)="onNext2()" type="submit" [disabled]="projectForm.form.invalid" >Next</button> -->
</div>
<div class="form-group row mt-5 justify-content-center">
<button type="submit" [disabled]="projectForm.form.invalid" class="btn btn-primary mt-3 col-md-2 col-sm-4"
>
Create project
</button>
</div>
</form>
onNext1(pr){
//console.log(pr.value);
return this.isShow1 = false, this.isShow2 = true;
}
onNext2(){
return this.isShow2 = false, this.isShow3 = true;
}
onNext3(){
return this.isShow3 = false, this.isShow4 = true;
}
onNext4(){
return this.isShow4 = false, this.isShow5 = true;
}
onNext5(){
return this.isShow5 = false, this.isShow6 = true;
}
onNext6(){
return this.isShow6 = false, this.isShow7 = true;
}
onCreateProject(projectForm : NgForm){
this.projectService.createProject(projectForm.value);
console.log(projectForm.value);
}
createProject(project : Pro){
return this.http.post('http://localhost:3700/api/project/addproject', project)
.subscribe(res => {
this.router.navigate(['/dashboard']);
});
}