简体   繁体   English

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

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

I have such directive: 我有这样的指示:

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

(as you can see also i'm using translate plugin) (你也可以看到我正在使用翻译插件)

and there i have a problem: in scope this value is changing, but it doesn't change in directive( 并且我有一个问题:在范围内这个值正在改变,但它在指令中没有改变(

when i'm using attrs-params (sure, if customDynamicText is a static string - all works) - but i have a dynamic variable customDynamicText 当我使用attrs-params(当然,如果customDynamicText是一个静态字符串 - 一切正常) - 但我有一个动态变量customDynamicText

How can i use this dynamic variable in directive template with ng-bind-html . 如何在ng-bind-html directive template使用此动态变量。

Is it possible? 可能吗?

Simply clever... I forgot to remove some quote-chars... So works: 简单聪明......我忘了删除一些引用字符...所以工作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM