angularjs – 角度平移翻译中的指令

前端之家收集整理的这篇文章主要介绍了angularjs – 角度平移翻译中的指令前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 angular-translate for i18n并希望在翻译中使用指令:

var translations = {
  TEST_1: 'Hello from <a href="/test">Test</a>',TEST_2: 'Hello from <user></user>'
};

app.directive('user',function() {
  return {
    template: '<a href="/test">Test</a>'
  };
});

完整的plnkr示例:http://plnkr.co/edit/jCCcvx7IEaAYUwyaQ7uH?p=preview

所以

<p translate="TEST_1"></p>
<p translate="TEST_2"></p>

应该是一样的.第一个(没有指令)工作,第二个没有.它转换了< user>< / user>,但Angular似乎并未意识到它并且没有执行其指令魔术.

解决方法

尝试使用translate-compile指令:

<p translate="TEST_2" translate-compile></p>

docs

Starting with version 2,the translation itself can be post processed in context of the current scope (using $compile). This means any directive used in a translation value itself will now work as expected.

猜你在找的Angularjs相关文章