What is the difference between *ngIf and [hidden]?

后端 未结 6 1083
名媛妹妹
名媛妹妹 2020-11-30 06:14

Say I check it against and expression, then aren\'t these two same ?

{{val}}
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 06:55

    Scenario :--> suppose you are using Behaviorsubject, and it emits boolean value "true/false".

    Case 1 --> *ngIf --> if Behaviorsubject returns initial value false, then it will disappear that DOM. and even if it emits true value later, it wont be visible.

    Case 2 --> Hidden --> it will work perfectly based on Behaviorsubject's emited value. i.e it will toggle the DOM.

    Note - *ngIf also toggles the DOM but on user's action or DOM event that toggles value of ngIf.

提交回复
热议问题