1

I get my article from database as json object. in this json I have my article data like title and body. I can show it in html page by {{title}} but my problem is about body. body contain HTML codes but the angular show it as string between 2 quotation. How can I solve it?

Angular controller code:

myApp.controller("articlePageController" , function($scope , $http        ,$location , $routeParams){
$http.get("/getArticle")
    .success(function(data) {
        $scope.body = data["article"]["body"];
        $scope.title = data["article"]["title"];
    })
    .error(function(data){
        console.log("no");
        $scope.currentArticle = data;
    });
});

Html view:

<h2>{{title}}</h2>
<p>{{body}}</p>

result:

 <p><iframe src="https://www.youtube.com/embed/9aOuF0-1KKY" width="560" height="315" frameborder="0" allowfullscreen=""></iframe></p>

the html code in result does not work as html code result image: enter image description here enter image description here

thinkdiff
  • 11
  • 4

2 Answers2

0

Use ngBindHtml

<p ng-bind-html="body"></p>
Adnan Umer
  • 3,669
  • 2
  • 18
  • 38
0

You need to use ng-bind-html to display html contents. https://docs.angularjs.org/api/ng/directive/ngBindHtml

Paulson Peter
  • 574
  • 4
  • 12