With ng-bind-html-unsafe removed, how do I inject HTML?

后端 未结 10 1998
不思量自难忘°
不思量自难忘° 2020-11-22 04:06

I\'m trying to use $sanitize provider and the ng-bind-htm-unsafe directive to allow my controller to inject HTML into a DIV.

However, I can

10条回答
  •  醉话见心
    2020-11-22 04:39

    1. You need to make sure that sanitize.js is loaded. For example, load it from https://ajax.googleapis.com/ajax/libs/angularjs/[LAST_VERSION]/angular-sanitize.min.js
    2. you need to include ngSanitize module on your app eg: var app = angular.module('myApp', ['ngSanitize']);
    3. you just need to bind with ng-bind-html the original html content. No need to do anything else in your controller. The parsing and conversion is automatically done by the ngBindHtml directive. (Read the How does it work section on this: $sce). So, in your case
      would do the work.

提交回复
热议问题