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

前端 未结 10 1448
别跟我提以往
别跟我提以往 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:12

    For Rails (at least in my case) if you are using the angularjs-rails gem, please remember to add the sanitize module

    //= require angular
    //= require angular-sanitize
    

    And then load it up in your app...

    var myDummyApp = angular.module('myDummyApp', ['ngSanitize']);
    

    Then you can do the following:

    On the template:

    %span{"ng-bind-html"=>"phone_with_break(x)"}
    

    And eventually:

    $scope.phone_with_break = function (x) {
      if (x.phone != "") {
       return x.phone + "
    "; } return ''; }

提交回复
热议问题