2

just a simple question.

let's take as IE this code :

<div *ngIf="1===2">
 ...some content
</div>

Is the content inside the NgIf rendered and then hide from the page or angular "knows" that this div is not gonna be displayed so doesn't even render the content inside it?

2
  • The content is not rendered to the DOM. See this question for more info Commented Apr 10, 2018 at 9:01
  • Please close your question by clicking the checkmark to the left of the answer that helped you most Commented Jun 24, 2018 at 18:38

2 Answers 2

2

*ngIf evaluates the expression and then renders the template in its place when the expression is truthy or falsy respectively. It adds and removes them physically from the DOM.
see this ngIf case study

Sign up to request clarification or add additional context in comments.

Comments

0

so answering your question

Placing the ngIf directive on a component, or element, will, in fact, hide or show that element based on the expression you pass it to be evaluated. Once evaluated, Angular will simply add or remove your DOM nodes, mount or remount your components, from the DOM - as the expression changes.

for an example when your page loads in dom and angular js is been called angular knows checks that this div is not gonna be displayed so doesn't even render the content inside it

also when you check in your element debugger you can see that div is hidden showing the comment of your condition.

detailed

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.