2016-11-16 86 views
1

我從數據庫中獲取我的文章作爲json對象。在這個json中我有我的文章數據,如標題和正文。我可以通過{{title}}在html頁面中顯示,但我的問題是關於body。正文包含HTML代碼,但角度顯示爲2引號之間的字符串。我該如何解決它?如何在Angularjs中將json響應顯示爲代碼而不是字符串?

角控制器代碼:

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視圖:

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

結果:

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

在結果的HTML代碼不爲HTML代碼 結果圖像工作: enter image description here enter image description here

+0

您可以查看https://docs.angularjs.org/api/ng/service/$sce –

+0

您目前面臨的問題是什麼? –

回答

相關問題