What is the equivalent of ngShow and ngHide in Angular 2+?

后端 未结 18 2434
离开以前
离开以前 2020-11-22 14:46

I have a number of elements that I want to be visible under certain conditions.

In AngularJS I would write

stuff
18条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 15:28

    Use the [hidden] attribute:

    [hidden]="!myVar"
    

    Or you can use *ngIf

    *ngIf="myVar"
    

    These are two ways to show/hide an element. The only difference is: *ngIf will remove the element from DOM while [hidden] will tell the browser to show/hide an element using CSS display property by keeping the element in DOM.

提交回复
热议问题