javascript – Convert JSON HTML string to HTML

javascript – Convert JSON HTML string to HTML

I think you need the Strict Contextual Escaping Service ($sce).
This is a service that enables you to specify the contexts in which it is O.K. to allow arbitrary HTML.

Docs: https://docs.angularjs.org/api/ng/service/$sce

Inject it in your controller:

app.controller(quizCtrl, function($rootScope, $scope, $http, $sce) 
...
$http.get(url5).then(function (response) {
    console.log(response.data);
    $sce.trustAsHtml = $sce.trustAsHtml; // <- needs to be exposed on $scope
    $scope.questions = $sce.trustAsHtml(response.data.questions);
})
...

And in your view:

{{questions}}

You need to use $sce service

$sce.trustAsHtml(varWithHTML)

to make binding html work.

As the docs says https://docs.angularjs.org/api/ng/service/$sce

javascript – Convert JSON HTML string to HTML

Leave a Reply

Your email address will not be published. Required fields are marked *