0

I'm setting a $scope variable to 0 or 1 based on a successful action and showing elements with ng-show. I'm resetting the $scope variable to empty when the step is finished. However, I have discovered that $scope = '' is shown as true if in interpolation {{$scope >= 0}}. Why not false?

controllers.Ctrl = function ($scope, $rootScope, $timeout, $filter, ajax, $parse) {

$scope.datachanged = '';
console.log($scope.datachanged >= 0); // true

};

1 Answer 1

0

That's just javascript for you. '' >= 0 will evaluate to true. This is because the empty string '' is falsy, and so is 0, so you can think of it as false >= false.

Instead, why don't you reset the variable to undefined (ie $scope.datachanged = undefined). undefined >= 0 will evaluate to false.

Alternatively, if the variable will only be set to 0 or 1, you could also just check to see if your variable equals 1 where you do the interpolation. {{datachanged === 1}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.