<div *ngIf="isVisible">Hello World</div>
If
isVisible is false, what will be rendered in the browser?<div *ngIf="isVisible">Hello World</div>The *ngIf directive removes the element from the DOM entirely when the condition is false. So nothing is rendered at all.
count is greater than 0?count > 0.Option A correctly uses *ngIf="count > 0" to check if count is greater than zero.
Option A checks if count is less than zero, which is wrong.
Option A uses assignment (=) which is invalid in *ngIf.
Option A checks if count equals zero, not greater than zero.
<div *ngIf="user.isLoggedIn">Welcome!</div>
and the component has
user = null;, what error will Angular throw?user = null;Accessing user.isLoggedIn when user is null causes a runtime TypeError because you cannot read properties of null.
flag = true;
and template:
<button (click)="flag = !flag">Toggle</button> <div *ngIf="flag">Visible</div>
What will the user see after clicking the button twice?
flag = true;Starting with flag true, first click sets flag false (div hidden), second click sets flag true again (div visible). So after two clicks, 'Visible' is shown.
*ngIf directive instead of toggling CSS display:none to hide/show elements?*ngIf removes the element from the DOM entirely, which means it is not processed by the browser or screen readers, improving performance and accessibility.
CSS display:none hides the element visually but keeps it in the DOM, which can cause unnecessary processing and accessibility issues.