I'm testing the ng-show
and AngularJS expressions, but I found something I can't understand. I created a variable displayed
and assigned a string 'false'
(not boolean) to it. The expression displayed && true
is evaluated to true, and the second div is shown without problem (because a string and true should be true). I know there are some differences between Angular expressions and JavaScript expressions, however I don't know why the first div is not shown; it seems that the displayed
is compiled to a boolean by Angular.
Here is the jsfiddle: http://jsfiddle.net/micmia/1psf70tv/3/
Template:
<div ng-controller="MyCtrl">
<div ng-show="displayed">test1</div>
<div ng-show="displayed && true">test2</div>
</div>
Controller:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope, $parse) {
$scope.displayed = 'false';
});
That's how angular evaluated the string 'false'
and 'f'
and some others as well.
There was an open bug about it.
See this fiddle works with a later version.
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