0

I am getting a below error when i try to do the below:

https://docs.angularjs.org/error/$parse/syntax?p0=%3C&p1=not%20a%20primary%20expression&p2=7&p3=%7Bleft:%3Cimageid,right:%20%3Eimageid,

Controller:

function MyCtrl($scope) {
    angular.forEach(document.querySelectorAll(".q"), function(val, key) {
        (function(key, val) {
         console.log(val.getAttribute("ng-class").replace(/\{{([ind]+)\}}/g, key));
      })(key, val);

    });
}
.ng-invalid { 
    border: 1px solid red; 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="">
  <div ng-controller="MyCtrl">
      <div ng-class="{x:{{ind}}<id,y:{{ind}} >id, z :{{ind}} == id}" class="q"></div>
      <div ng-class="{x:{{ind}}<id,y:{{ind}} >id, z :{{ind}} == id}" class="q"></div>
  </div>
</div>

The above code prints fine in console replacing {{ind}} values perfectly, but when the application executes i get the below error:

Syntax Error: Token '<' not a primary expression at column 7 of the expression [{x:id,] starting at [{4}].

9
  • Can you explain, what are you trying to do? Commented Nov 25, 2016 at 21:19
  • 1
    I mean the big picture - are you trying to modify ng-class expression while the application is running? Commented Nov 25, 2016 at 21:23
  • 2
    This is not a coding pattern I have ever seen. If the variable ind is dynamic, you don't need {{}} curly braces. Just use the variable as is. It's highly unlikely that anything you want to achieve requires this weird pattern. Commented Nov 25, 2016 at 21:26
  • 2
    @JoelCDoyle: The point is i am just trying to replace the {{ind}} with regular expression, in this case it does not matter whether its {{}} or plain ind. Commented Nov 25, 2016 at 21:28
  • 1
    This will not work, as far as I know, because angular does replacement magic by itself when it is constructing the DOM. so, you may have to construct your own directives and look at the compiler to achieve something like this. Commented Nov 25, 2016 at 21:33

1 Answer 1

2

I think angular is trying to tell you that you have to pass the div as a string.

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.