Reputation: 945
I have a simple template in angular js:
<div>{{post}}</div>
where post is an embedded code of one of my posts which I pulled of my facebook profile. the "post" property is set in the scope of the controller related to the div. When I load the page I get the embedded code as text.
Then after doing some reading I tried doing it like so:
<div ng-bind-html="post"></div>
and
<div ng-bind-html-unsafe="post"></div>
now the embedded html code is set into the page's html code but the post is not shown. it is as if it is set there but not loaded or something.
by the way if I set the code itself in the template the post is loaded and shown as needed, it just that from time to time I would like to change the post and What am I missing here? thanks
Upvotes: 0
Views: 734
Reputation: 13918
I guess that it doesn't work because the post
scope property is sanitized.
Try to inject $sce
service into your controller and add this line:
$scope.post = $sce.trustAsHtml($scope.post);
$sce.trustAsHtml
returns an object that is trusted by angular for use in specified strict contextual escaping contexts such as ng-bind-html, ng-include...
Upvotes: 1