0

Walking through a tutorial app for use with the Ionic platform, which is built on angular 1.2.4, I've hit a confusing error in this Angular markup:

    <content has-header="true" scroll="false">
      <list>
        <item ng-repeat="project in projects" ng-click="selectProject(project)" ng-class="{active:activeProject==project}">
          {{project.title}}
        </item>
      </list>
    </content>

The error in chrome console is:

Error: [$parse:syntax] Syntax Error: Token 'itemClass' is an unexpected token
at column 33 of the expression [{active:activeProject==project} itemClass] 
starting at [itemClass].

If you change the ng-class attribute thusly (add a semicolon) :

       <item ng-repeat="project in projects" 
        ng-click="selectProject(project)" 
        ng-class="{active:activeProject==project};">

then the error goes away.

The ionic forum users are wondering why this is. I've found lots of SO posts on ng-class, and reviewed the docs, but nowhere can I find evidence that the trailing semicolon is a requirement, e.g. this post.

My best guess is that Angular is jamming (minifying) the class code together with something else and a semicolon is not being inserted automatically before javascript tries to run it; but the Angular docs say it doesn't use eval(), so it's puzzling how it fails.

Would love to know why this is happening.

1
  • 1
    Add a plunker please. Commented Jan 7, 2014 at 20:27

1 Answer 1

0

This was happening to me when my directive (item in this case) was configured with replace: true, and both the directive and the element it was replacing were using the ng-class directive. I guess angular was jamming the ng-class properties together in a way that led to a syntax error.

This could have been what was going on here, depending on the definition of the item directive.

The fix (workaround) was to set replace: false.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.