What is the difference between ng-if and ng-show/ng-hide

前端 未结 12 1556
执笔经年
执笔经年 2020-11-22 02:22

I\'m trying to understand the difference between ng-if and ng-show/ng-hide, but they look the same to me.

Is there a differenc

12条回答
  •  独厮守ぢ
    2020-11-22 03:18

    1. ng-if if false will remove elements from DOM. This means that all your events, directives attached to those elements will be lost. For example, ng-click to one of child elements, when ng-if evaluates to false, that element will be removed from DOM and again when it is true it is recreated.

    2. ng-show/ng-hide does not remove the elements from DOM. It uses CSS styles (.ng-hide) to hide/show elements .This way your events, directives that were attached to children will not be lost.

    3. ng-if creates a child scope while ng-show/ng-hide does not.

提交回复
热议问题