When to favor ng-if vs. ng-show/ng-hide?

前端 未结 7 1452
陌清茗
陌清茗 2020-11-22 08:39

I understand that ng-show and ng-hide affect the class set on an element and that ng-if controls whether an element is rendered as par

7条回答
  •  无人及你
    2020-11-22 09:04

    If you use ng-show or ng-hide the content (eg. thumbnails from server) will be loaded irrespective of the value of expression but will be displayed based on the value of the expression.

    If you use ng-if the content will be loaded only if the expression of the ng-if evaluates to truthy.

    Using ng-if is a good idea in a situation where you are going to load data or images from the server and show those only depending on users interaction. This way your page load will not be blocked by unnecessary nw intensive tasks.

提交回复
热议问题