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
Post a Comment