P
P
Pavel Fedotov2014-11-20 14:04:21
JavaScript
Pavel Fedotov, 2014-11-20 14:04:21

AngularJS, How to output HTML data from JSON if ngBind doesn't help?

A JSON file like this comes from the server:

{
  "text": "<p style='color: #0000ff; padding: 30px;'>Guide</p>", 
  "name": "Post" 
}

The data goes to the server from TinyMCE.
I tried outputting with ngBindand ngBindHtml, but it ended up outputting <p>Guide</p>.
Why are they lost style='color: #0000ff; padding: 30px;'?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-11-20
@zex713

https://docs.angularjs.org/api/ngSanitize/service/...

S
Sergey Romanov, 2014-11-20
@Serhioromano

To solve this problem, make a special you can create a special filter. At least this is my choice for solving this problem

.filter('asHTML', function($sce) {
  return function(input) {
    return $sce.trustAsHtml(input);
  };
})

Now in the code you can simply.
or
<span ng-bind-html="var | asHTML"></span>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question