PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

Angular · Theory

Conditional

← All stacks

Theory

11/43

Conditional

*ngIf shows or removes a node. false → gone from the DOM, not just hidden. [hidden] only hides with CSS. Know the difference.

Board: *ngIf="marks >= 40; else failTpl". 0 is falsy — *ngIf="marks" hides a zero score. Write *ngIf="marks != null" if zero is valid.

New control flow @if (marks >= 40) { … } does the same idea. Trap: *ngIf on a huge block that you really wanted to hide visually but keep alive (audio, focus).

Diagram
  marks >= 40 ?
     │ yes → Pass banner
     │ no  → Fail template
  *ngIf removes DOM
Exam tip

*ngIf vs hidden. Watch 0.

Example

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

@Component({
  selector: "app-root",
  template: `
    <h1>{{ title }}</h1>
    <button (click)="toggle()">Toggle</button>
    <p *ngIf="open">Panel open</p>
  `,
})
export class AppComponent {
  title = "Angular practice";
  open = true;
  toggle() {
    this.open = !this.open;
  }
}

Conditional: toggle open. Say whether the panel is on screen after one click.

Short notes

  • Def*ngIf adds/removes DOM. Not the same as [hidden].
  • RuleZero can be falsy. Compare explicitly.
  • Trap*ngIf="marks" when 0 is a real score.
  • ExPass banner vs Fail template.

Questions

1

*ngIf vs [hidden]?

2

Why can *ngIf="marks" hide 0?

Previous← EventsNextLists →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.