1

I have a image path in AngularJs $scope variable imageUrl, which comes from external source.

http://farm6.staticflickr.com/5579/14671096893_806ec359b7_m.jpg

I am trying to get the image on HTML page.

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

But when I am trying to run this in firefox, it is giving me error

"NetworkError: 403 Forbidden - http://localhost/demo/view/html/%5B%22http://farm6.staticflickr.com/5579/14671096893_806ec359b7_m.jpg%22%5D"

Its taking root path of project. How can I make some changes to show image on the web page?

0

3 Answers 3

3

If you look at the error that was generated, it contains some url encoded characters as well. I entered it into a Url Decoder and this is what the image url string actually looks like.

http://localhost/demo/view/html/["http://farm6.staticflickr.com/5579/14671096893_806ec359b7_m.jpg"]

Notice the bracket and quote characters?

This leads me to believe that $scope.imageUrl contains the [""] symbols. You can easily test this out by rendering the value in a <pre> tag next to the <img> tag like so...

<img ng-src="{{imageUrl}}">
<pre>{{imageUrl}}</pre>

If the value in the rendered <pre> tag has the [""] symbols, then the solution is to remove those symbols from the $scope.imageUrl property.

You can remove these symbols from imageUrl like so...

$scope.imageUrl = $scope.imageUrl.replace(/[\[\"\]]/g, "");

However, if you're using the $http service to retrieve this data from the Flickr API, you should consider using the transformResponse option which allows you to manipulate data (in your case, strip out bad characters from the imageUrl) from an http request before resolving the promise.

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

3 Comments

Do you know how they are getting there in the first place?
Its coming from the Flickr API.
I updated my answer with an example of how you could strip the unwanted characters. - It would be interesting to see the code you're using to retrieve the data from Flickr
0

I have created a fiddle and it is working perfectly in chrome and firefox. Hope it solves your problem

Fiddle

HTML Markup:

<div ng-app>
    <div ng-controller="test">
        <img ng-src="{{imageUrl}}">
    </div>
</div>

2 Comments

Yes it runs with html. But creating problem with server.
@Ankit: Seeing your error again you need to remove the localhost url so from localhost/demo/view/html/%5B%22http://farm6.staticflickr.com/…" you need to have farm6.staticflickr.com/5579/14671096893_806ec359b7_m.jpg%22%5D"
0

html-

<div ng-app>
  <div ng-controller="test">
    <img ng-src="{{imageUrl}}">
    </div>
  </div>      
</div>

js-

function test($scope){

     $scope.imageUrl = 'https://angularjs.org/img/AngularJS-small.png';

  }

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.