0

I'm an angular noob here... but enjoying figuring it out. I have simple json file containing text like so:

   "gettingstarted":{
      "title":"Getting Started",
      "content":"<img ng-src='images/pageone-snorkeler.png' width='150' height='107' alt='Snorkeler' /><p>Getting Started...... and a lot of other html in here...</p>"
   },"etc..."

I am trying to load images into the rendered html, however, angular seems to be stripping the src and ng-src from my html.

My page.tpl.html file looks like so:

<h1 ng-bind-html="page.title"></h1>
<div ng-bind-html="page.content"></div>

I am loading / using:

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.min.js"></script>

I can see all the html render in the page correctly from the json data, however, not the image. It is rendering like so:

<img width='150' height='107' alt='Snorkeler' />

What am I missing to get images to load in my html?

EDIT:::: Looks like I needed to word my question different... I found the answer here: ng-bind-html does not load image src

ng-bind-html-unsafe

...which isn't working for me... or use the fully resolved url: http://superraddomainname.com/image/image.png for example.

1

1 Answer 1

1

ng-bind-html-unsafe has been removed in angular 1.2. What you've done with ng-bind-html should work, you have to make sure you add ngSanitize as a dependency in your app. For example...

angular.module('myApp', ['ngSanitize']);

Demo - Fiddle

2
  • Thanks for the comment! As long as I load it from the full URL, no problem. If i try and load locally, it doesn't show. Commented Jun 30, 2014 at 20:23
  • Just noticed that the img tag was using ng-src. Make sure that's src. Commented Jun 30, 2014 at 20:43

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.