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

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

    You can use filter like this

    angular.module('app').filter('trustAs', ['$sce', 
        function($sce) {
            return function (input, type) {
                if (typeof input === "string") {
                    return $sce.trustAs(type || 'html', input);
                }
                console.log("trustAs filter. Error. input isn't a string");
                return "";
            };
        }
    ]);
    

    usage

    it can be used for other resource types, for example source link for iframes and other types declared here

提交回复
热议问题