Insert HTML with scripts that should run

前端 未结 2 938
独厮守ぢ
独厮守ぢ 2020-12-03 03:38

One part of this app gets HTML back from the server that needs to be shown as live HTML. That\'s easily done with the ng-bind-html-unsafe=\"expression\" directi

相关标签:
2条回答
  • 2020-12-03 04:28

    You need jQuery (load it before Angular):

    "we looked into supporting script tags in jqlite, but what needs to be done to get a cross-browser support involves a lot of black magic. For this reason we decided that for now we are just going to recommend that users use jquery along with angular in this particular case" -- https://groups.google.com/d/msg/angular/H4haaMePJU0/5seG803by5kJ

    See also AngularJS: How to make angular load script inside ng-include?

    0 讨论(0)
  • 2020-12-03 04:43

    I can propose my variant. First you should create directive:

    app.directive('html', [ function () {
      return {
        restrict: 'A',
        link: function (scope, element, attrs) {
          element.html(attrs.html);
        }
      }
    }]);
    

    Then you can use it inside tag.

    <div html="{{code}}"></div>
    
    0 讨论(0)
提交回复
热议问题