I'm new to both javascript and AngularJS, and wondering why is the expression inside the quotes not evaluated?
<span ng-show="{{remaining()}}!==0">sometext</span>
it is simply printed like this:
<span ng-show="2!==0">sometext</span>
and the ng-show is not working regardless of the contents. The text ( and the printed expression) is shown even if the expression is wrapped in an eval, :
eval("{{remaining()}}!==0")
I resorted to creating a function in my controller for this:
<span ng-show="renderOrNot()">sometext</span>
which works, but I would prefer not to have to write a function each time I want to make a comparison
The ng-show and ng-hide both are directive . The difference between is : ng-show directive will show the html element if expression resilts is true and ng-hide directive hide the html element if expression result is true .
AngularJS ng-hide Directive The ng-hide directive hides the HTML element if the expression evaluates to true. ng-hide is also a predefined CSS class in AngularJS, and sets the element's display to none .
The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements.
The ng-src directive should be used instead of src if you have AngularJS code inside the src value. The ng-src directive makes sure the image is not displayed wrong before AngularJS has evaluated the code.
Almost there ...
When you use {{}}
, the values are interpolated, i.e. the markup is replaced with the result of the expression. ngShow expects only the expression, so just use the function as it is, and it will work:
<span ng-show="remaining() !== 0">sometext</span>
In general, you'll only want {{ }}
when your expression / content should be displayed.
You must not use it {{}}
because your value is bind. Use ng-show
like this:
<span ng-show="remaining() !== 0">sometext</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With