0

Following is my AngularJS table code, which is filling the trs like -

<tbody class="no-bd-y">
  <tr ng-repeat="emp in empData">
    <td>{{emp.first_name}}</td>
    <td>{{emp.last_name}}</td>
    <td><img src="{{siteurl}}:3030/public/{{emp.prof_image}}" width="120" height="120" ng-if="emp.prof_image" class="img-responsive"></td>
  </tr>
</tbody>

Now the problem is when I firebug the page, 2 URLs are formed for every image -

http://example.com:8000/%7B%7Bsiteurl%7D%7D:3030/public/%7B%7Bemp.prof_image%7D%7D

http://example.com:3030/public/a1419c564308370f8d4817b7885ce031.png

Console -

Going On

As you can see now, every image is forming 2 GET and as previous one is not correct the page load time increase. Let me know how could I fix this problem ?

EDIT

Following is my controller code -

angular.module("app").controller("MyController", function($scope, $location, SessionService, $http) {
    $scope.user = SessionService.currentUser;
    $scope.siteurl = $location.absUrl().split(":8000/")[0];

    // Get user listing
    $http.get("/api/getempl").then(function(response){
        if (response.status == 200) {
            console.log(response.data.data);
            $scope.empData = response.data.data;       
        }
        else {
            console.log('400');
        }
    });

});
4
  • can you show us your controller or scope called emp ? Commented Sep 8, 2014 at 9:45
  • @Vladimir yeah sure..let me add that code Commented Sep 8, 2014 at 9:47
  • @Vladimir Please find my edit Commented Sep 8, 2014 at 9:51
  • Try to make this function inside module app and return the result like it explained here stackoverflow.com/questions/18184026/… Commented Sep 8, 2014 at 9:56

2 Answers 2

2

You are using src directly, and since angular doesn't run before the dom is ready it is trying to fetch the src. Use ng-src instead which doesn't set the src attribute until angular can process it.

<img ng-src="{{siteurl}}:3030/public/{{emp.prof_image}}"...
Sign up to request clarification or add additional context in comments.

1 Comment

Wow ..this fixed my problem..+1 and a green tick
1

Try to use ng-src, it should help

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.