Angular 19 tutorial in Hindi #16 ElseIf Conditions Angular | control flow statement | @elseif

Define Property and Html for If else condition

Apply If else condition

Hide and show with button click

Toggle with button click

Update button text with toggle

Interview Question

A "property" in the context of an if-else condition refers to a characteristic or attribute of an object or data that can be evaluated to determine whether a condition is true or false. This property's value will be used in the condition part of the if statement.


<h1>If Else | Control Flow</h1>

<!-- @if(val>5){
<div style="background-color: gold; height: 200px; width: 200px;">

</div>
} -->

<button (click)="hide()">Hide </button>
<button (click)="show()">Show </button>
<button (click)="toggle()">Toggle </button>

<button (click)="toggle()">
{{display?'hide':'show' }}</button>


@if(display){
<div style="background-color: green; height: 200px; width: 200px;">

</div>
}

<hr>


<button (click)="toggleDivs()">Toggle Divs</button>
@if(displayOneDiv){
<div style="background-color: blue; width: 100px; height: 100px;">

</div>

}
@else{
<div style="background-color: red; width: 100px; height: 100px;">

</div>
}


import { Component } from '@angular/core';

@Component({
selector: 'app-root',
imports: [],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent {
display=true
val=10;
displayOneDiv=true

hide(){
this.display=false
}
show(){
this.display=true
}
toggle(){
this.display= !this.display
}
toggleDivs(){
this.displayOneDiv=!this.displayOneDiv
}
}