I have a below html code. ( I do not intend to use *ngFor )
<div *ngIf = 'showTemplate1'>Template 1</div>
<div *ngIf = 'showTemplate2'>Template 2</div>
<div *ngIf = 'showTemplate3'>Template 3</div>
<div *ngIf = 'showTemplate4'>Template 4</div>
<div *ngIf = 'showTemplate5'>Template 5</div>
<div *ngIf = 'showTemplate6'>Template 6</div>
<div *ngIf = 'showTemplate7'>Template 7</div>
<div *ngIf = 'showTemplate8'>Template 8</div>
In my TS file, I have as below
displayTemplates(){
if( condition1 ){
this.showTemplate1 = true;
this.showTemplate2 = true;
this.showTemplate3 = true;
this.showTemplate4 = true;
this.showTemplate5 = true;
this.showTemplate6 = true;
this.showTemplate7 = false;
this.showTemplate8 = false;
}
else if( condition2 ){
this.showTemplate1 = false;
this.showTemplate2 = true;
this.showTemplate3 = true;
this.showTemplate4 = true;
this.showTemplate5 = true;
this.showTemplate6 = true;
this.showTemplate7 = false;
this.showTemplate8 = true;
}
else if( condition3 ){
this.showTemplate1 = true;
this.showTemplate2 = true;
this.showTemplate3 = true;
this.showTemplate4 = true;
this.showTemplate5 = true;
this.showTemplate6 = true;
this.showTemplate7 = true;
this.showTemplate8 = false;
}
}
As you see in the code, it looks like a bad code. Is there any other approach to make this much cleaner and SCALABLE.