Bird
0
0

How can you conditionally display a paragraph only if the component property isVisible is true in the template?

hard📝 Application Q8 of 15
Angular - Components
How can you conditionally display a paragraph only if the component property isVisible is true in the template?
A<p *ngIf="isVisible">Visible content</p>
B<p [hidden]="isVisible">Visible content</p>
C<p (isVisible)>Visible content</p>
D<p {{ isVisible }}>Visible content</p>
Step-by-Step Solution
Solution:
  1. Step 1: Recall Angular structural directive for conditional display

    *ngIf directive shows or hides elements based on a condition.
  2. Step 2: Identify correct syntax for *ngIf

    Using *ngIf="isVisible" displays the paragraph only when isVisible is true.
  3. Final Answer:

    <p *ngIf=\"isVisible\">Visible content</p> -> Option A
  4. Quick Check:

    *ngIf controls element presence by condition [OK]
Quick Trick: Use *ngIf="condition" to show/hide elements [OK]
Common Mistakes:
  • Using [hidden] which hides but keeps element in DOM
  • Using parentheses which are for events
  • Trying to interpolate condition inside tag

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes