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

后端 未结 10 1995
不思量自难忘°
不思量自难忘° 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:40

    Instead of declaring a function in your scope, as suggested by Alex, you can convert it to a simple filter :

    angular.module('myApp')
        .filter('to_trusted', ['$sce', function($sce){
            return function(text) {
                return $sce.trustAsHtml(text);
            };
        }]);
    

    Then you can use it like this :

    And here is a working example : http://jsfiddle.net/leeroy/6j4Lg/1/

提交回复
热议问题