是否可以在 ng-class 中声明注释
Is it possible to declare comment inside of ng-class
我有一个问题是否可以在 ng-class
中声明注释
ng-class="{'test':true,'test1':true, //some comment 'test2':true}"
好像没有。您可能需要像这样使用多行注释语法:
<div ng-class="{'test':true,'test1':true, /* some comment */ 'test2':true}"></div>
但这会引发错误:
Syntax Error: Token '*' is unexpected, expecting [:] at column 29 of the expression [{'test':true,'test1':true, /* some comment */ 'test2':true}] starting at [* some comment */ 'test2':true}].
不过,您可以通过在 controller/directive 中声明您的样式来解决此问题:
$scope.styles = {
'test': true,
'test1': true,
/* some comment */ 'test2': true
};
包括您认为的:
<div ng-app="MyApp">
<div ng-controller="MyCtrl">
<div ng-class="styles"></div>
</div>
</div>
不,无法在 JSON 或 HTML 中的 ng- 表达式中进行注释,因此如果您需要注释,请在周围的某个地方使用标准 HTML(不是在标签内在参数之间,它将 "crash")。在标签之前或之后使用它。但请记住,评论将对查看您页面源代码的用户可见。在发布前使用一些 uglify 工具删除生产中的评论。
我有一个问题是否可以在 ng-class
中声明注释ng-class="{'test':true,'test1':true, //some comment 'test2':true}"
好像没有。您可能需要像这样使用多行注释语法:
<div ng-class="{'test':true,'test1':true, /* some comment */ 'test2':true}"></div>
但这会引发错误:
Syntax Error: Token '*' is unexpected, expecting [:] at column 29 of the expression [{'test':true,'test1':true, /* some comment */ 'test2':true}] starting at [* some comment */ 'test2':true}].
不过,您可以通过在 controller/directive 中声明您的样式来解决此问题:
$scope.styles = {
'test': true,
'test1': true,
/* some comment */ 'test2': true
};
包括您认为的:
<div ng-app="MyApp">
<div ng-controller="MyCtrl">
<div ng-class="styles"></div>
</div>
</div>
不,无法在 JSON 或 HTML 中的 ng- 表达式中进行注释,因此如果您需要注释,请在周围的某个地方使用标准 HTML(不是在标签内在参数之间,它将 "crash")。在标签之前或之后使用它。但请记住,评论将对查看您页面源代码的用户可见。在发布前使用一些 uglify 工具删除生产中的评论。