My controller holds a description which is plain HTML code. I want this to be injected into a given tag so that it is rendered according to the tags it contains.

I tried the following but the HTML is rendered in the attribute whereas I expected to be into the tag itself.

<div ng-bind-html-unsafe="{{stage.description}}"></div>
有帮助吗?

解决方案 2

I don't remember since when AngularJS does not allow this anymore.

What you need to do is to include the AngularJS Sanitize library. You can download the sanitize library somewhere here: https://code.angularjs.org/1.2.16/

In your module

angular.module('myModule', ['ngSanitize'])

In your template

<div ng-bind-html="stage.description"></div>

其他提示

Remove the curly braces. The curly braces is just the templating tags. You want to bind the actual variable.

<div ng-bind-html-unsafe="stage.description"></div>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top