1

So I'm trying to change the source of the image depending on an expression to see if its true or not.

HTML

<img ng-src="category.content.Value >= category.content.ValueOneWeekAgo ? 
'Images/green_arrow.png' : 'Images/red_arrow.png'" />

This is how the rendered html looks like:

<img ng-src="category.content.Value >= category.content.ValueOneWeekAgo ? 'Images/green_arrow.png' : 'Images/red_arrow.png'" 
src="category.content.Value &gt;= category.content.ValueOneWeekAgo ? 'Images/green_arrow.png' : 'Images/red_arrow.png'">

I know the variables contains values which was confirmed by debugging. Probably something simple but i can't seem to figure it out.

2
  • what more do you want me to explain? Commented Jan 26, 2015 at 9:41
  • do you want to change the ng-src value from controller? Commented Jan 26, 2015 at 9:44

1 Answer 1

1

You can just switch the order in you expresssion to use < instead of >=. You cannot use >= because browser treats it as end of html tag.

<img ng-src="category.content.ValueOneWeekAgo < category.content.Value  ? 'Images/green_arrow.png' : 'Images/red_arrow.png'" >

Other option is to put this code inside a controller and publish as new variable on $scope.

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

3 Comments

The result is identical to the rendered html I wrote above, part from the order of <=
thats what i ended up doing. ng-src="{{getArrowSrc(category.content.Value, category.content.ValueOneWeekAgo) }}"
You don't need {{}} to call a function. I think you can have other markup errors in you template that are causing error in ng-src attribute.

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.