0

I've created one jsfiddle for the same jsfiddle

sample HTML code

<div ng-app="myAppModule" ng-controller="someController">
<!-- Show the name in the browser -->
<!-- Bind the input to the name -->
<span ng-bind="showImage"></span>
</div>
<script>

</script>

sample angular js code

var myApp = angular.module('myAppModule', []);
myApp.controller('someController', function($scope) {
// do some stuff here
$scope.showImage="<a class='fancybox' href='http://i.imgur.com/9VFmFrN.jpg' data-fancybox-group='gallery' title='Personalized Title'><img class='MaxUploadedSmallSized' src='http://i.imgur.com/9VFmFrNs.jpg' alt=''></a>";

I'm trying to render image from angular js model on front end UI but it is coming as text.

I've tried $compile property of angular js too but that is not working too.

snapshot

enter image description here

4
  • You should not do it like this. HTML must be in HTML, not in JS. Commented Aug 20, 2014 at 11:19
  • then what is the correct approach ? Commented Aug 20, 2014 at 11:20
  • 1
    If you want to show/hide something, put it in HTML and use ngShow/ngHide directives. You don't want to pollute JS with representation. Commented Aug 20, 2014 at 11:22
  • and if you want to load template use ng-include Commented Aug 20, 2014 at 11:36

1 Answer 1

1

Add a data structure to your controller that contains the relevant informations:

$scope.showImage=[];
$scope.showImage.Link='http://i.imgur.com/9VFmFrN.jpg';
$scope.showImage.Source='http://i.imgur.com/9VFmFrN.jpg';     
$scope.showImage.Title='Personalized Title';

The access it in your html as if you are using a template engine:

<div>
  <a class='fancybox' ng-href='{{showImage.Link}}' data-fancybox-group='gallery' title='{{showImage.Title}}'><img class='MaxUploadedSmallSized' ng-src='{{showImage.Source}}' alt=''></a>
</div>

Look here: Fiddle

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

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.