Câu hỏi phỏng vấn Angular
Câu hỏi

What is the equivalent of ngShow and ngHide in Angular?

Câu trả lời

In Angular, the equivalents of the AngularJS directives ngShow and ngHide are primarily handled by the [hidden] attribute and the *ngIf structural directive.

  1. [hidden] Attribute: This attribute is used to control the visibility of elements in Angular. It works by setting the CSS display property of the element. If the expression assigned to [hidden] evaluates to true, the element is hidden; if false, the element is displayed. However, it's important to note that the [hidden] attribute does not remove the element from the DOM; it merely changes its display style to none[1][2][5].

    Example:

    html Copy
    <div [hidden]="!isVisible">This content is conditionally visible</div>
  2. *ngIf Directive: Unlike the [hidden] attribute, *ngIf actually adds or removes elements from the DOM based on the truthiness of the expression provided. If the expression evaluates to true, the element is added to the DOM; if false, the element is removed. This approach is more performance-efficient when the visibility of an element changes frequently, as it re...

junior

junior

Gợi ý câu hỏi phỏng vấn

middle

What is Subscribing?

senior

What is Ivy Renderer?

middle

What is a Parameterized pipe?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào