Why use ng-hide when ng-show can work in both situations

I looked at so many questions how, but I got this only solution that ng-showby default hides the element and shows it if the condition is true and on the other side it ng-hideshows the element by default and hides it when the condition is true.

But my concern is that the condition can be taken care of with the help ng-showor ng-hideonly if we use different things.

for instance

I've seen this somewhere in the code, the user is using ng-show, and ng-hidethe two

<div ng-init="isShow = 'one'">
    <a href="#" ng-click="isShow == 'one' ? isShow = 'two' : isShow = 'one'">
    <div ng-show="isShow=='one'">
        If One show this
    </div>
    <div ng-hide="isShow=='one'">
        If Two show this
    </div>
</div>

But for me this can be achieved with this code.

<div ng-init="isShow = 'one'">
    <a href="#" ng-click="isShow == 'one' ? isShow = 'two' : isShow = 'one'">
    <div ng-show="isShow=='one'">
        If One show this
    </div>
    <div ng-show="isShow=='two'">
        If Two show this
    </div>
</div>

. - , ng-show ng-hide. - ?

!

+4
2

, - . . AngularJS "" . 90% , , ng-hide="thatcondition" , hdiden. HIDDEN, ng-show="thatrarecondition" .

, , AngularJS. ! , , , >, <, >=, <= .. , .

, "" , -. JS , . , , , - ( ). , DIV, :

<div ng-show="{{ object.details }}">
    <!-- Render object.details here -->
</div>

"" . , , . :

<div ng-hide="{{ order.shipped }}">
   Want to cancel this order? <a href="...">click here</a>
</div>

? , undefined/null order.shipped ! , /, . DATE, ? ! ( ) .

+5

. AngularJS ngShow

: " ngShow HTML- , ngShow. CSS.ng-hide CSS . CSS .ng-hide AngularJS ( ).

ngHide: AngularJS ngHide

: " ngHide HTML- , ngHide. , ng-hide CSS . ng-hide CSS- AngularJS none ( ).

, Angular DOM: http://www.w3schools.com/angular/angular_htmldom.asp

, , . , , . , : <div ng-show="value1 && !value2">Something</div>. , , , .

<div ng-show="ShowMe()">Content</div>

$scope.ShowMe = function(){
    return $scope.value && !$scope.value2;
}
+1

Source: https://habr.com/ru/post/1651997/


All Articles