Angularjs display value with html

26,221

Solution 1

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");

Solution 2

You should use the ng-bind-html directive, you can read more here

<div ng-controller="TestCtrl" ng-bind-html="{value}">

Share:
26,221
A191919
Author by

A191919

Updated on May 27, 2020

Comments

  • A191919
    A191919 almost 4 years

    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>
    
  • Jagz W
    Jagz W over 5 years
    <span ng-bind="value"></span> this work for me.