在这种情况下更好 ng-hide/show 或 ng-if?
in this case is better ng-hide/show or ng-if?
我在我的应用程序中使用 Angular 和 Ionic,我在 ng-show
上遇到了一些问题,所以我决定更改并使用 ng-if
,现在我的应用程序是按我的意愿工作,但我有一些疑问。性能怎么样?我正在做的是正确的吗?
这就是我现在的代码:
<div ng-if="betSlip.length >= 1">
<div class="list betslip-item">
<div class="item item-divider betslip-header">
APPLY TO ALL
</div>
我是这样的:
<div ng-show="betSlip.length >= 1">
<div class="list betslip-item">
<div class="item item-divider betslip-header">
APPLY TO ALL
</div>
更新
ng-switch
呢?
ng-show/hide 仅将 display:none 样式应用于您的组件,但 DOM 元素仍然存在,并且仍然存在,另一方面,ng-if 会创建 DOM 元素只有在满足条件时,ng-if 或 show 哪个更好取决于一些因素,often/fast 是如何切换条件的,这是基于用户交互还是基于非常快速变化的计算计算?还有,你的切换元素有多少个绑定?
这是我的标准,何时使用其他
1 if the container is simple(none, or few bindings) and my dom is not too crowded already and doesn't have required fields or is not contained inside a form i am ok using hide/show
2 if my element contains a lot of bindings, my DOM is aleady extense, or the existance of the the content affects some how the result of the application ie(required fields or submit buttons inside a form) then i use ng-if or ng-switch
这些没有记录,但我选择处理 dom insertions/display
我在我的应用程序中使用 Angular 和 Ionic,我在 ng-show
上遇到了一些问题,所以我决定更改并使用 ng-if
,现在我的应用程序是按我的意愿工作,但我有一些疑问。性能怎么样?我正在做的是正确的吗?
这就是我现在的代码:
<div ng-if="betSlip.length >= 1">
<div class="list betslip-item">
<div class="item item-divider betslip-header">
APPLY TO ALL
</div>
我是这样的:
<div ng-show="betSlip.length >= 1">
<div class="list betslip-item">
<div class="item item-divider betslip-header">
APPLY TO ALL
</div>
更新
ng-switch
呢?
ng-show/hide 仅将 display:none 样式应用于您的组件,但 DOM 元素仍然存在,并且仍然存在,另一方面,ng-if 会创建 DOM 元素只有在满足条件时,ng-if 或 show 哪个更好取决于一些因素,often/fast 是如何切换条件的,这是基于用户交互还是基于非常快速变化的计算计算?还有,你的切换元素有多少个绑定?
这是我的标准,何时使用其他
1 if the container is simple(none, or few bindings) and my dom is not too crowded already and doesn't have required fields or is not contained inside a form i am ok using hide/show
2 if my element contains a lot of bindings, my DOM is aleady extense, or the existance of the the content affects some how the result of the application ie(required fields or submit buttons inside a form) then i use ng-if or ng-switch
这些没有记录,但我选择处理 dom insertions/display