I'm using angularjs to make my first web application.
I'm retreiving data from server as JSON object, and i'm trying to display in HTML page. The json objet looks like :
{
"title":"news1",
"description":"La fédération du <strong>Malawi<\/strong> n’a pas trop attendu pour remercier le sélectionneur <strong>Young Chimodzi<\/strong> après la défaite à domicile face au <strong>Zimbabwe.<\/strong>\ <br\/>\ <br\/>Le technicien local a été placé en congés jusqu’à la fin de son contrat qui expire à la fin de juillet prochain. La raison est simple, la défaite surprise face au Zimbabwe 1-2 lors de la première journée de la phase éliminatoire de la Coupe d’Afrique des nations Orange 2017.\ <br\/>\ <br\/>L’instance du pays a annoncé qu’un successeur à <strong>Young Chimodzi<\/strong> sera nommé le 1er aout prochain. Alors que l’intérim sera assuré par <strong>Ernest Mtawali.<\/strong>\"
}
I'm using a simple ng-repeat to dislay text :
<div ng-rpeat="n in news">
<p>{{n.description}}</p>
</div>
I'm using a simple json request :
$http.get("http://www.server/news", {headers: {
'Content-Type': 'application/json'
}, })
.success(function (response) {
$scope.news = response;
});
I tried to change the content type and to play with it but no changes
the text is not well formed it's showing like that :
You want to render the html. For that you need angular sanatize library.
Add angular-sanatize.js in your html, and in your module add dependency of ngSanatize.
And update your html to
<p ng-bind-html="n.description"></p>
For details, refer to - https://docs.angularjs.org/api/ng/directive/ngBindHtml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.