Is it possible to declare a comment inside an ng class?

I have a question, is it possible to declare a comment inside an ng class

ng-class="{'test':true,'test1':true, //some comment 'test2':true}" 
+6
source share
2 answers

This is not like that. You would need to use multi-line comment syntax like this:

 <div ng-class="{'test':true,'test1':true, /* some comment */ 'test2':true}"></div> 

But this causes an error:

Syntax error: token "*" is unexpected, waiting for [:] in column 29 of expression [{'test': true, 'test1': true, / * some comment * / 'test2': true}] starting with [* some comment * / 'test2': true}].

However, you can get around this by declaring your styles in your controller / directive:

 $scope.styles = { 'test': true, 'test1': true, /* some comment */ 'test2': true }; 

And including this, in your opinion:

 <div ng-app="MyApp"> <div ng-controller="MyCtrl"> <div ng-class="styles"></div> </div> </div> 

JsFiddle example

+6
source

No, you cannot comment inside JSON or ng expressions in HTML, so if you need to do this, use standard HTML somewhere (not inside the tag between the parameters, it will "crash"). Use it before or after the tag. But remember that comments will be visible to users viewing the source code of your page. Use some uglify tool before release to remove these comments during production.

0
source

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


All Articles