Insert HTML into view from AngularJS controller

前端 未结 18 2286
Happy的楠姐
Happy的楠姐 2020-11-21 06:00

Is it possible to create an HTML fragment in an AngularJS controller and have this HTML shown in the view?

This comes from a requirement to turn an

18条回答
  •  天命终不由人
    2020-11-21 06:43

    ng-bind-html-unsafe no longer works.

    This is the shortest way:

    Create a filter:

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

    And in your view:

    P.S. This method doesn't require you to include the ngSanitize module.

提交回复
热议问题