我正在使用
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.