Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs display value with html [duplicate]

How to display Html from value? Like @Html.Raw() in ASP.NET. Because in current example i get only text with tags.

JS:

var app = angular.module('Demo', []);
app.controller('TestCtrl', function ($scope) {
    $scope.value = '<p>List</p><ul><li>Test 1</li><li>Test 2</li><li>Test 3</li><li>Test 4</li></ul>'
});

view:

<div ng-controller="TestCtrl">
    {{value}}
</div>
like image 647
A191919 Avatar asked Sep 06 '25 09:09

A191919


1 Answers

use

<div ng-bind-html="value"></div>

instead of

{{value}}

you have to use $sce provider to process your code to get a safe context.

$scope.value= $sce.trustAsHtml("yourHtmlCode");
like image 196
Simon Schüpbach Avatar answered Sep 08 '25 23:09

Simon Schüpbach