AngularJS:翻译和多个ng-bind-html值

时间:2015-08-24 11:33:24

标签: javascript angularjs translate

在我的应用程序中,我尝试连接两个字符串:电子邮件和一些文本。

但我遇到麻烦,我需要文本部分可翻译“动态”所以我写道:

$scope.textUnsubscribe = 'SUCESSFULL_UNSUBSCRIBE';

在视图中:

<h4 ng-bind-html="textUnsubscribe | translate"></h4>

我确定可以(电子邮件+文字):

<h4 ng-bind-html="userEmail"></h4>
<h4 ng-bind-html="textUnsubscribe | translate"></h4>

然后我有风格错误......

我可以以某种方式放入一个ng-bind-html两个范围变量吗?一个是“静态的”,第二个是可翻译的?

喜欢:

<h4 ng-bind-html="userEmail, (textUnsubscribe | translate)"></h4>

1 个答案:

答案 0 :(得分:6)

如果它只是简单的字符串,如电子邮件。您不需要ng-bind-htmlng-bind就足够了。添加-html会使ng-bind更安全。无论如何ng-bind可以多次使用。如果你有一个&#34;风格的错误&#34;有了它,它来自你的HTML(你有多个h4)。

无论如何,你可以在一个简单的ng-bind上这样做:

<h4 ng-bind="userEmail +' '+ (textUnsubscribe | translate)"></h4>