1
 src={{logo}}

var logo = 'localhost:3000/modules/images/default.png'

I am displaying the image path dynamicaly but its not showing path in html, Do i need to use quotes for src?Can anyone please help me.

1
  • For quotes:- <figure> <img src="img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228"> <figcaption>Fig.1 - A view of the pulpit rock in Norway.</figcaption> </figure> Commented Dec 27, 2016 at 13:18

3 Answers 3

7

Use ng-src

<img ng-src="{{logoUrl}}">

This gives you expected result, because phone.imageUrl is evaluated and replaced by its value after angular is loaded.

<img src="{{logoUrl}}">

But with this, the browser tries to load an image named {{phone.imageUrl}}, which results in a failed request. You can check this in the console of your browser.

var app=angular.module("myApp",[]);
app.controller('myCtrl',function($scope){
  $scope.logo='https://angularjs.org/img/AngularJS-large.png';
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <div>
    <img ng-src="{{logo}}" />
  </div>
</div>

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

3 Comments

I am not getting the image displayed with the abovee code.
@nlr_p that was localhost URL(Accessible only from your system). I have added other URL which is accessible. Please check
@nir_p You can check the output in the code snippet.
1
<img ng-src={{logo}}/>

$scope.logo = 'localhost:3000/modules/images/default.png'

Comments

0

simply use ng-src..

$scope.logo = 'localhost:3000/modules/images/default.png';

 <img ng-src="{{logo}}">

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.