How do you use $sce.trustAsHtml(string) to replicate ng-bind-html-unsafe in Angular 1.2+

前端 未结 10 1442
别跟我提以往
别跟我提以往 2020-11-22 03:51

ng-bind-html-unsafe was removed in Angular 1.2

I\'m trying to implement something where I need to use ng-bind-html-unsafe. In the docs and

10条回答
  •  旧巷少年郎
    2020-11-22 04:04

    var line = "";

    1. use filter

    app.filter('unsafe', function($sce) { return $sce.trustAsHtml; });
    

    using (html):

    
    ==>click `aaa` show alert box
    

    2. use ngSanitize : safer

    include angular-sanitize.js

    
    

    add ngSanitize in root angular app

    var app = angular.module("app", ["ngSanitize"]);
    

    using (html):

    
    ==>click `aaa` nothing happen
    

提交回复
热议问题