Comments in angularjs expression

I have HTML tags that have ng-clicks and ng-ifs. Inside the corresponding expressions, I make function calls and pass parameters, some of which are literals (mostly just true or false). So I would like to add a comment as to what literal means, but angular does not seem to be able to parse this correctly. (I understand that passing literals is not a bright idea, but I still would like to know the answer)

<button class='someclass' ng-click='somefunction(val1, val2, true /* explanation for literal */)' > </button> 

How to add comments to angular expressions?

+5
source share
3 answers

No, comments are not supported. Parser sees / as a mathematical operator (see source code ) that expects a primary expression after it: for example, something starts with ( or [ etc. etc. However, in javascript there is no valid expression that can include * immediately after the / character Thus, the parser throws an exception: Token '*' not a primary expression .

+2
source

While Angular documentation does not explicitly say that JavaScript comments are not supported. I would suggest that this is not so.

Angular Expressions are just a subset of some JavaScript (and some additional features like filters).

+1
source

Why can't you pass these comments as separate parameters instead of adding other parameters? Even if you do, it will not be a very good design.

-1
source

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


All Articles