AngularJS指令:具有范围值的模板(ng-bind-html)

AngularJS directive: template with scope value (ng-bind-html)

本文关键字:ng-bind-html 指令 范围 AngularJS      更新时间:2023-09-26

我有这样的指令:

...
template: function(element, attrs) {
    var htmlTemplate = '<div class="start-it" ng-if="isVisible">'
          <p ng-bind-html="''{{customDynamicText}}'' | translate"></p>'
        </div>';
    return htmlTemplate;
},
...

(正如你所看到的,我正在使用翻译插件)

我有一个问题:在范围内,此值正在更改,但在指令(

当我使用 attrs-params 时(当然,如果 customDynamicText 是一个静态字符串 - 一切都有效) - 但我有一个动态变量customDynamicText

我如何在directive template中使用此动态变量与ng-bind-html.

可能吗?

简直聪明...我忘了删除一些引号字符...所以有效:

...
<p ng-bind-html="' + attrs.customDynamicText + ' | translate"></p>'
...