JSON response:
post: {
body: "<div>O meu html vem dessa forma</div>"
}
I would like to know how I can render this% my post.body
in my view. Is there any directive that will do this for me ???
JSON response:
post: {
body: "<div>O meu html vem dessa forma</div>"
}
I would like to know how I can render this% my post.body
in my view. Is there any directive that will do this for me ???
With this kind of response in HTML format you would need to load the angle in ngSanitize
and use tag
for loading ng-bind-html
( angular.module('app', ['ngSanitize']);
).
Minimum example:
var app = angular.module('app', ['ngSanitize']);
app.controller('ctrl', ['$scope', function($scope)
{
$scope.result = '';
$scope.submit = function()
{
var post = {
body: "<div>O meu <i>html</i> <b>vem</b> dessa forma</div>"
}
$scope.result = post.body;
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-sanitize.js"></script><divng-app="app" ng-controller="ctrl">
<p ng-bind-html="result"></p>
<a href="#" ng-click="submit();">Clique para carregar</a>
</div>
See this example in the fiddle, you will need a decode in the body variable and an append in the element that will receive the html: link
If you have not yet done so, you can use ng-bind-html