2

I am using angular 4 and is stuck at a point. I am using below code in html component to display data in a table:

<table class="table">
<thead>
    <tr>
      <th>Code</th>
      <th width="22%">Description</th>
      <th>Requested <br> Date</th>
      <th>Status</th>
      <th width="15%">Status change Date</th>
      <th width="10%">User ID</th>
      <th width="31%">Comments</th>
      <th></th>
    </tr>
</thead>
<tbody>
    <tr *ngFor="let orm of ormData">
      <td>{{orm.code}}</td>
      <td class="specialWidth">{{orm.description}}</td>
      <td>{{orm.reqDate}}</td>
      <td>{{orm.status}}</td>
      <td>{{orm.statusChngDate}}</td>
      <td>{{orm.userId}}</td>
      <td>{{orm.comments}}</td>
      <td><img src={{orm.img}} alt="delete" height=30px" width="30px"></td>
    </tr>
</tbody>

and this is the ormData from ts component:

ormData = [{
'code':'AP1',
'description':'AP Translated and attested by SM',
'reqDate':'29/11/2016',
'status':'pending',
'statusChngDate':'13/12/2016',
'userId':'User ID',
'comments':'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ipsam in.',
'img':'assets/icons/deleteGrey.svg'

}];

Now in my output am getting all data as expected except for the image. Instead of the image text content <img src="assets/icons/deleteGrey.svg" alt="delete" height=30px" width="30px"> is being displayed.

Kindly let me know how can I get my image displayed in the output.

4
  • I see you have 'img':'assets/icons/deleteGrey.svg'. Can you use a .svg extension with <img />? Commented Jun 21, 2017 at 17:32
  • Nevermind.. I guess thats valid. developer.mozilla.org/en-US/docs/Web/HTML/Element/img Commented Jun 21, 2017 at 17:33
  • Do you mean that the actual text "<img..." is being displayed? Commented Jun 21, 2017 at 17:45
  • yes, actual text "<img..." was getting displayed. Seems the correct syntax to use here is <img [src]='orm.img' ...> After that it is working properly Commented Jun 22, 2017 at 10:45

1 Answer 1

3

You are missing "" at the height attribute,

 <td><img [src]='orm.img'  height="30px" width="30px">
 </td>

DEMO

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

8 Comments

thanks for your quick response @Sajeetharan. I tried your method but still getting this in the output instead of the image <img [src]='orm.img' alt="delete" height=30px" width="30px">
still getting what ?
do you have a valid url?
yes, If I remove ngFor from the <tr> then image loads properly but if I keep the ngFor it doesn't
Are you really sure there's a difference between [src]="foo" and src="{{foo}}"?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.