Pradeep Pradeep - 1 year ago 121
AngularJS Question

The tilde operator not working in angularjs?

The tilde operator

not working in
directive but I can check the condition like this
message.indexOf('angular') > 0
I want to know why the tilde operator not working inside the HTML.

In the html:

<div ng-if="~message.indexOf('angular') ? true : false">...</div>

In the angularJS:

$scope.message = 'Hello angular';

Error appears in the console

angular.js:13920 Error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 0-0 [~] in expression [~message.indexOf('angular') ? true : false].$parse/lexerr?p0=Unexpected%20nextharacter%20&p1=s%200-0%20%5B~%5D&p2=~message.indexOf('angular')%20%3F%20true%20%3A%false
at Lexer.throwError (
at Lexer.lex (
at AST.ast (
at ASTCompiler.compile (
at Parser.parse (
at $parse (
at ChildScope.$watch (
at (

Answer Source

Angular's template expression syntax is much like JavaScript expression syntax, but it's still not JavaScript.

The key differences are listed in the documentation and one of them states

  • No Bitwise, Comma, And Void Operators: You cannot use Bitwise, , or void operators in an Angular expression.

Being a bitwise operator, ~ is not supported.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download