My code is working but I would know is there another solution to show and hide input without using many Boolean variables and many functions?
My code type script:
I have three inputs and I need to show the second input when the first input value is not empty:
import { Component, OnInit } from '@angular/core'
@Component({
selector: 'app-takwa',
templateUrl: './takwa.component.html',
styleUrls: ['./takwa.component.css']
})
export class TakwaComponent implements OnInit {
show1=false
show2=false
show3=false
constructor() { }
ngOnInit() {
this.show1=true
}
showSecondInput(){
this.show1=false
this.show3=false
this.show2=true
}
showThirdInput(){
this.show1=false
this.show3=true
this.show2=false
}
showFirstInput(){
this.show1=true
this.show3=false
this.show2=false
}
}
My HTML code :
<form action="">
<div *ngIf="show1">
<input formControlName="test1" value="test1">
<button (click)="showSecondInput()">suivant</button>
</div>
<div *ngIf="show2">
<input formControlName="test2" value="Test2">
<button (click)="showThirdInput()">suivant</button>
<button (click)="showFirstInput()">retour</button>
</div>
<div>
<div *ngIf="show3">
<input formControlName="test3" value="Test3">
<button (click)=" showSecondInput()">retour</button>
</div>
</div>
</form>
demo images