Bitwise Angular Expression not working

I have a basic ng-show expression as follows:

ng-show="((message.status & messageStatus.Spam) != 0)" 

However, this fails with the following message: "Token & unexpectedly, waiting []] in column 18 of the expression . "

Does Angular support bitwise operations, or do I need to write a function to evaluate something as simple as that?

+6
source share
3 answers

From the banal list of angularjs github: https://github.com/angular/angular.js/issues/2838

http://docs.angularjs.org/guide/expression "Angular Expressions against JS expressions It might be tempting to think of Angular expressions as JavaScript expressions, but this is not entirely correct, because Angular does not use JavaScript eval () to evaluate expressions."

You can use a filter to achieve the effect as such:

 angular.module('project', []) .filter('bitwiseAnd', function () { return function (firstNumber, secondNumber) { return ((parseInt(firstNumber, 10) & parseInt(secondNumber, 10)) === parseInt(secondNumber, 10)); // return firstNumber % secondNumber > 0 }; }); 
+5
source

It does not support according to the doc .

Thought he mentioned '|' in the document, but do not confuse, '|' non-bitwise OR is Angularjs filter .

+1
source

you can use * /% with primes instead of | & ^ with bits

I use these expressions:

 ng-class="{'active':(filter% 2 )}" ng-click="filter = filter % 2 ? filter * 2 : filter / 2" ng-class="{'light':(filter % 2)}" class="fa fa-eye" 

With prime numbers 2, 3 and 5

you should start with $scope.filter=1

0
source

Source: https://habr.com/ru/post/950931/


All Articles