Loading

Quipoin Menu

Learn • Practice • Grow

angular / ngIf Directive
mcq
Direction: Choose the correct option

Q1.

What does `*ngIf='condition'` do?
A. Creates a loop
B. Adds a class
C. Hides the element using CSS
D. Renders the element if condition is true, removes if false
Direction: Choose the correct option

Q2.

How do you provide an else template with `*ngIf`?
A. Using `ngIfElse`
B. Both A and C
C. Using `else` with a template reference
D. Using `ng-template` with `#elseBlock`
Direction: Choose the correct option

Q3.

What is the difference between `*ngIf` and `[hidden]`?
A. They are identical
B. `*ngIf` removes/adds element; `[hidden]` just hides with CSS
C. `*ngIf` is for loops
D. `[hidden]` is faster
Direction: Choose the correct option

Q4.

Can you use `*ngIf` with asynchronous data?
A. Only in services
B. Only with observables
C. Yes, often with the `async` pipe
D. No, it only works with synchronous data
Direction: Choose the correct option

Q5.

What does `*ngIf='user$ | async as user'` do?
A. Unsubscribes automatically
B. Creates a local variable
C. Subscribes to observable, stores result in 'user' variable, and renders if truthy
D. All of the above
Direction: Choose the correct option

Q6.

What is the purpose of the `then` clause in `*ngIf`?
A. To specify else template
B. To create then block
C. To chain conditions
D. To specify a template to render when condition is true
Direction: Choose the correct option

Q7.

What is `` used for?
A. To define template blocks that can be used with structural directives
B. To define CSS
C. To create new components
D. To define routes
Direction: Choose the correct option

Q8.

What happens if the condition in `*ngIf` is initially false?
A. Nothing
B. An error occurs
C. The element is not created in the DOM
D. The element is created but hidden
Direction: Choose the correct option

Q9.

Can you use `*ngIf` with `ngSwitch`?
A. No, they conflict
B. Yes, they can be combined on different elements
C. Only on same element
D. Only with ng-container
Direction: Choose the correct option

Q10.

What is the `ngIf` directive's impact on performance?
A. It has no impact
B. It causes memory leaks
C. It improves performance by not rendering unnecessary elements
D. It slows down rendering