angularjs - ng-show expression: comparing multiple strings using || -


can please explain why works:

<div ng-repeat="fruit in fruits">     <span ng-hide="fruit.type == 'apple' || fruit.type == 'banana'">         {{fruit.type}}      </span> </div> 

renders:

pear lemon  

but doesn't:

<div ng-repeat="fruit in fruits">     <span ng-hide="fruit.type == 'apple' || 'banana'">         {{fruit.type}}      </span> </div> 

renders:

// nothing 

in javascript (and languages know), comparisons aren't communicable. every comparison (in case equality), unfortunately need full statement.

in fruit.type == 'apple' || 'banana',
1. fruit.type == 'apple' evaluated.
2. after that, || compares result of 'banana', in javascript truthy value ('' "falsy" string, other strings "truthy").

in essence, end fruit.type == 'apple' || true, trigger ng-hide.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -