简体   繁体   English

angularjs表达式中的注释

[英]Comments in angularjs expression

I have some HTML tags which have ng-clicks and ng-ifs. 我有一些HTML标签,其中包含ng-clicks和ng-ifs。 Inside the respective expressions, I make function calls and pass in parameters, some of which are literals (mostly just true or false). 在各个表达式中,我进行函数调用并传入参数,其中一些是文字(大多数是真或假)。 So I would like to add a comment as to what a literal means, but angular doesn't seem to be able to parse this correctly. 所以我想添加一个关于字面意思的注释,但angular似乎无法正确解析它。 (I realize passing literals is not the brightest idea but I would nevertheless like to know the answer) (我意识到传递文字不是最明智的想法,但我仍然想知道答案)

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

How do I add comments in angular expressions? 如何在角度表达式中添加注释?

No, comments are not supported. 不,不支持评论。 Parser sees / as an mathematical operator (see source code ) which expects primary expression after it: eg something starting with ( , or [ , etc. However there is no valid expression in javascript that can include * immediately after / character. So parser throws an exception: Token '*' not a primary expression . 解析器看到/作为一个数学运算符(参见源代码 ),它需要在它之后的主表达式 :例如以( ,或[等等)开头的东西。但是javascript中没有有效的表达式可以包含*紧跟在/字符之后。所以解析器抛出例外: Token '*' not a primary expression

While the Angular documentation doesn't explicitly say that JavaScript comments are not supported. 虽然Angular文档没有明确说明不支持JavaScript注释。 I would assume they are not. 我认为他们不是。

Angular Expressions are only a subset of some JavaScript (and some added features like filters). 角度表达式只是某些JavaScript的一个子集(以及一些添加的功能,如过滤器)。

Why can't you pass these comments as separate parameters instead of appending other parameters? 为什么不能将这些注释作为单独的参数传递而不是附加其他参数? Even though you achieve doing this somehow it would be not very good design. 即使你以某种方式实现这一点,它也不是很好的设计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM