ng-bind-html vs bind-html-compile?

前端 未结 1 1892
[愿得一人]
[愿得一人] 2020-12-21 23:11

I want to know the difference between ng-bind-html and bind-html-compile directives. For example I gave

test

1条回答
  •  庸人自扰
    2020-12-21 23:37

    bind-html-compile is not a standard Angular directive, it comes with the module https://github.com/incuna/angular-bind-html-compile and it is used to compile binded data.To make it simple, it is equivalent to write html in your source code: it will be re-evaluated and if other directives are found, they will work as expected.

    ng-bind-html is a standard directive (bundled with Angular itself) and just output html strings without compiling it.

    for example, if you controller has a variable with plain html, like in:

    $scope.dataToDisplay = '

    Title

    ';

    Then you can go with ng-bind-html.

    If you need to inject variables that contain html with other directives, such as:

    $scope.dataToDisplay = '

    Title

    ';

    then you need to aforementioned module.

    0 讨论(0)
提交回复
热议问题