I have sầu gone through so many questions like this but got this only solutions that ng-show by mặc định hides the element and show it if condition is true and on the other hvà ng-hide by mặc định show the element & hide it when condition is true.

Bạn đang xem: Á»©ng dụng show hàng

But my concern is the condition can be taken care of with ng-show or ng-hide only then why we use different things.

For example

I saw this somewhere in this code user is using ng-show và ng-hide both

So what exactly is the difference between both the codes. There must be some specific difference if ng-show and ng-hide both exists. Anyone know it?

Thanks in advance!



I don"t see any reason for this question to be downvoted - it"s a valid thought. The reason is simple, though. AngularJS has "declarative" as one of its core philosophies. If 90% of the time you want an element shown, but occasionally it should be hidden, ng-hide="thatcondition" clearly indicates when it should be hdiden. If most of the time it should be HIDDEN, then ng-show="thatrarecondition" is more readable.

Xem thêm: Lương Y Nguyễn Hữu Toàn Lừa Đảo, Lương Y Nguyễn Hữu Toàn

Clear, readable code is an important principle in any framework, và especially in AngularJS. The ! operator is narrow & easily missed, far more than any of the other comparisons like >, =, , etc. Providing positive- và negative-visibility operators makes it much more readable what"s going on here.

An important detail to lớn note is that both directives look for "truthy" values, not exactly-equal ones. JS is pretty vague about this, & sometimes that"s an advantage. For example, suppose you have an object that may have a sub-object (a detail element). You might have the detail-display DIV written as follows:

This "truthy" comparison is also handy for the negative case. Suppose you want to lớn HIDE an order-cancellation blochồng in a sales system if the order has been shipped. Consider:

Why is this important? Well, it means ANY non-undefined/null value for order.shipped will hide this block! That means if today, you mix it as a true/false, it will work. But tomorrow you change it lớn a DATE that the order was shipped? The rule will still work! This makes it easy to code (và maintain) displays like this.