Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to declare comment inside of ng-class

I have a question is it possible to declare comment inside of ng-class

ng-class="{'test':true,'test1':true, //some comment 'test2':true}"
like image 633
Shaxrillo Avatar asked May 29 '15 07:05

Shaxrillo


1 Answers

It doesn't appear to. You would have needed to use the multiline comment syntax like so:

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

But that throws an error:

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}].

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

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

And including that in your view:

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

jsFiddle Example

like image 133
CodingIntrigue Avatar answered Oct 10 '22 00:10

CodingIntrigue