0

i am new to angularjs. i am trying to display a table with some data read from a db. one of the pieces of data i receive from DB is called IS_LOCKED. if it's 1, i want to display an image of a locked padlock, else display an image of an unlocked padlock.

if i do the following in angular where i write out "LOCKED" and "UNLOCKED", the output table is correct:

    <tr ng-repeat="x in retData.projects | orderBy:'NAME'">
            <td>{{ x.NAME }}</td>
            <td>{{ x.IS_LOCKED==1 ? "LOCKED" : "UNLOCKED" }}</td>
    </tr>

if i do the if statement and print out the url, it doesn't work....i get the code back and both images display, ie: "{{ x.IS_LOCKED===1 ? (locked padlock image here) : (unlocked padlock image here)}}"

  <tr ng-repeat="x in retData.projects | orderBy:'NAME'">
         <td>{{ x.NAME }}</td>
         <td>{{ x.IS_LOCKED==1 ? <img src=./images/padlock_locked.png width=20 height=20> : <img src=./images/padlock_unlocked.png width=20 height=20>}}</td>
  </tr>

tried doing some ng-switch and other things, but kept getting compile errors. sorry, new to angular...not sure if i am doing this correctly. anyone know how to do this right?

1 Answer 1

1

Use ng-src

<td><img ng-src="{{(x.IS_LOCKED == 1) ? './images/padlock_locked.png' : './images/padlock_unlocked.png'}}" width=20 height=20></td>
Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome, please mark the question as answered if there are no more pending queries.

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.