Angular Html Template

Hello,

I have created an Angular HTML template to display, among other things, html that is stored in a field. The template displays the field . . . as markup. In other words, it doesn’t parse it as html.

Is there a way to tell ng-bind-html to render the html?

I am using:

ng-bind-html=“indexPattern.formatField(hit, ‘markup’) | trustAsHtml”

Thank you! :slight_smile:

FYI:

Investigate Version: 11.1.4
Federate Version: 7.6.2-20.2 on ES 7.6.2

Okay, after futzing with the template a bit more, it appears that the “offender” is the (Siren?) indexPattern.formatField(…) call. For instance, if I change a “simple” field from:

ng-bind-html=“indexPattern.formatField(hit, ‘title’) | trustAsHtml”

to

ng-bind=“indexPattern.formatField(hit, ‘title’)”

I see the tags that surround the value of “title” are not parsed as html (i.e., it dumps the markup to the page).

So I need to get Siren or Angular or BOTH to simply dump the contents of my “markup” field to the page so that it is parsed as html.

I dearly hope I am making sense here. :slight_smile:

Is there any documentation on the API that indexField supports?

Hi Richard,

You can display the html formatted value from the field into your template using this code:

ng-bind-html="hit._source.html_field | trustAsHtml"

Here is the template:

<div style="word-wrap: break-word;">
  <div ng-repeat="hit in hits|limitTo:limit track by hit._index+hit._type+hit._id+hit._score" class="snippet"
    style="border:1px #ddd solid; margin: 4px; padding: 4px">
    
    <div ng-bind-html="hit._source.html_field | trustAsHtml" ></div>
  
  </div>
</div>

Documentation for html-angular template.

Regards
Manu

Thanks. That works. The example I used had

ng-bind-html=“indexPattern.formatField(hit, ‘html_field’) | trustAsHtml”

which will not format as HTML.

Might want to put some more template examples up. :wink:

1 Like