0

I have json data having anchor tag .

task.json

{
    "data": [{
        "id": 1,
        "title": "Launch an EC2 Instance",
        "desc": "Needed an <a href='#'>EC2</a> instance to deploy the ccr code",
        "status": "done",
        "percentage_finished": 100
    }]
}

I am using angularjs to render this data to my html page . But anchor tag is not working. It prints as it is as Text.

<div class="task-pn panel panel-primary">
     <div class="panel-heading"><b>Description : Task-{{task_detail.id}}</b></div>
     <div class="panel-body"> 
         <div onclick="this.contentEditable='true';">{{task_detail.desc}}</div>  
     </div>
</div> 

Output img.

enter image description here

I need a simple link to EC2 word .How to deal with this isuue?

Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68
Anil Arya
  • 3,100
  • 7
  • 43
  • 69

2 Answers2

1

You need something like this:

In your controller:

scope.trustedHtml = sce.trustAsHtml(json.desc);

And to use it in your partial:

<p class="org-desc" ng-bind-html="trustedHtml"> </p>
user2720708
  • 455
  • 2
  • 8
  • 19
0

user2720708 :Thanks for sharing your ideas.

eRIZ gave this link .There I used the idea of Luke Madera.

Current working html page .

<div class="task-pn panel panel-primary">
   <div class="panel-heading"><b>Description : Task-{{task_detail.id}}</b></div>
   <div class="panel-body"> 
      <div contentEditable" ng-bind-html="task_detail.desc"></div>  
   </div>
</div> 

and Then I follow only two steps :

1.include the angular-sanitize.min.js resource, i.e.:

2.In a js file (controller or usually app.js), include ngSanitize, i.e.: angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'ngSanitize']) ---------from answer given by Luke Madera

Its working now ...:)

Community
  • 1
  • 1
Anil Arya
  • 3,100
  • 7
  • 43
  • 69