我有一个问题,是否可以在 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 /指令中声明样式来解决此问题:
$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>
关于javascript - 是否可以在 ng-class 中声明注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30523455/