2

I'd stuck at a point while working with ng directives. I'm passing two parameters to mouseoverOnStep function, one is object value itself and second one is the selector of the element. I've the following HTML code

<li ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-{{Color.id}}');" ng-repeat="Color in select.Color">&nbsp;</li>

What I am getting the output when I inspected my element. It is

<li ng-repeat="Color in select.Color" ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-');" class="ng-scope">&nbsp;</li>

With

Error: [$parse:syntax] 

Why I am not getting the value of {{Color.id}} in DOM ? I am expecting something like.

ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-12');"
ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-13');"

Any help would be appreciated.

1
  • You don't put a brace expression in the function, it is already accepting an angular expression. so change it to pass in the Color.id and in the function concatenate it with '.mask-second-' Commented Jul 10, 2015 at 7:33

1 Answer 1

2

This is already an angular expression:

ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-{{Color.id}}');"

Putting {{ }} into javascript isn't valid.

You have 2 options:

ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-'+ Color.id);"

This won't evaluate and show the value of Color.id, and why should it? it is the same as writing this function in JavaScript:

function showMeId(value) { console.log(value); }

showMeId('.mask-second-' + Color.id); // in javascript you will never see that evaluated.

-- OR --

ng-mouseover="mouseoverOnStep(Color);"

your mouseoverOnStep:

function mouseoverOnStep(color) {
    var cssClass = '.mask-second-' + Color.id;
}

I think you're getting confused with what is JavaScript and what is HTML and what gets evaluated.

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

2 Comments

Pardon your first answer did not work for me. It is giving the output ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-'+ Color.id);" instead ng-mouseover="mouseoverOnStep(Color.color_value, '.mask-second-12');". For your second answer I will only have to go with that. I was trying to make a global function so you can call this from everywhere (Views)..
It won't replace the value, it hasn't been executed by javascript... I'm not sure what you're asking....

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.