正确使用NG-节目和NG隐藏相同的DOM元素?元素、正确、节目、NG

由网友(怪我闹@)分享简介:我在想,如果是用NG-节目和NG隐藏相同的DOM元素一个很好的做法。I was wondering if is a good practice to use ng-show and ng-hide on the same DOM element.这似乎是一个更好的了解,而不是使用多个条件,其中的一些被否定,在一个单...

我在想,如果是用NG-节目和NG隐藏相同的DOM元素一个很好的做法。

I was wondering if is a good practice to use ng-show and ng-hide on the same DOM element.

这似乎是一个更好的了解,而不是使用多个条件,其中的一些被否定,在一个单一的NG-显示

It seems a better idea, instead of using multiple conditions, some of which negated, in a single ng-show.

让我知道。谢谢!

Let me know. Thanks!

PS:这里的例子

< D​​IV NG秀=isBlondeNG隐藏=hasBlueEye> Mary是金发碧眼,她有绿色的眼睛< / DIV>

推荐答案

绝对不是。

首先,这两个指令可以在彼此跳闸(请参阅本 的jsfiddle ,作为提供通过 乔尔Skrepnek ),一般只是糟糕的设计。

First of all, the two directives can trip over each other( see this JSFiddle, as provided by Joel Skrepnek), and is generally just bad design.

您可以使用一个函数,另一场或者只是一些更多的嵌入式逻辑。

You can use a function, another field or just some more inline-logic.

直列逻辑:的

Inline-Logic:

<div ng-show="isBlonde && !hasBlueEye">Mary is blonde and she has green eyes</div>

的 字段:的

Field:

<div ng-show="shouldShowThisDiv">Mary is blonde and she has green eyes</div>

功能的

Function

<div ng-show="shouldShowThisDiv()">Mary is blonde and she has green eyes</div>

$scope.shouldShowThisDiv = function(){
    return $scope.isBlonde && !$scope.hasBlueEye;
}

我的建议会为使用另一个字段或功能后,如果有需要检查超过2的值。

My recommendation would be to use either another field or a function, if there are more than 2 values that needs to be checked.

阅读全文

相关推荐

最新文章