• Overview
@angular/common

NgIf

directive

A structural directive that conditionally includes a template based on the value of an expression coerced to Boolean. When the expression evaluates to true, Angular renders the template provided in a then clause, and when false or null, Angular renders the template provided in an optional else clause. The default template for the else clause is blank.

  
    class NgIf<T = unknown> {}
  
  

ngIf

T

The Boolean expression to evaluate as the condition for showing a template.

ngIfThen

A template to show if the condition expression evaluates to true.

ngIfElse

A template to show if the condition expression evaluates to false.

ngTemplateGuard_ngIf

"binding"

Assert the correct type of the expression bound to the ngIf input within the template.

The presence of this static field is a signal to the Ivy template type check compiler that when the NgIf structural directive renders its template, the type of the expression bound to ngIf should be narrowed in some way. For NgIf, the binding expression itself is used to narrow its type, which allows the strictNullChecks feature of TypeScript to work with NgIf.

ngTemplateContextGuard

boolean

Asserts the correct type of the context for the template that NgIf will render.

The presence of this method is a signal to the Ivy template type-check compiler that the NgIf structural directive renders its template with a specific context type.

@paramdirNgIf<T>
@paramctxany
@returnsboolean
Jump to details