AngularJS:在指令后的模板中插入字符串
AngularJS: Interpolate string in template after directive
我在模板上应用翻译并使用 "translate" 指令,如下所示:
<span translate>Hello {{name}}!</span>`
在德语的单独 de.json 文件中,我有像 {"Hello {{name}}!": "Hallo {{name}}!"}
这样的翻译键值对。
在运行时,我的 "translate" 指令假设将 "span" 中的内容替换为 "Hallo {{name}}!",然后 AngularJS 需要插入模板字符串。
不幸的是,今天它的工作方式相反:第一个 AngJS 插值,然后应用我的指令。
问题:在 AngJS 中有没有办法设置我的指令在 AngularJs 运行插值之前应用?
来自AngularJS Interpolation Guide:
the interpolateDirective
has a priority of 100
and sets up the watch in the preLink` function
来自AngularJS $compile Docs:
priority
When there are multiple directives defined on a single DOM element, sometimes it is necessary to specify the order in which the directives are applied. The priority is used to sort the directives before their compile functions get called. Priority is defined as a number. Directives with greater numerical priority are compiled first. Pre-link functions are also run in priority order, but post-link functions are run in reverse order. The order of directives with the same priority is undefined. The default priority is 0
.
Angular 翻译库在 $translateProvider API 中有一个 directivePriority(priority)
函数,允许您将指令配置为 运行 的更高优先级,例如 101
.这应该让你的 translate
指令在插值之前变为 运行。
我在模板上应用翻译并使用 "translate" 指令,如下所示:
<span translate>Hello {{name}}!</span>`
在德语的单独 de.json 文件中,我有像 {"Hello {{name}}!": "Hallo {{name}}!"}
这样的翻译键值对。
在运行时,我的 "translate" 指令假设将 "span" 中的内容替换为 "Hallo {{name}}!",然后 AngularJS 需要插入模板字符串。
不幸的是,今天它的工作方式相反:第一个 AngJS 插值,然后应用我的指令。
问题:在 AngJS 中有没有办法设置我的指令在 AngularJs 运行插值之前应用?
来自AngularJS Interpolation Guide:
the
interpolateDirective
has a priority of100
and sets up the watch in the preLink` function
来自AngularJS $compile Docs:
priority
When there are multiple directives defined on a single DOM element, sometimes it is necessary to specify the order in which the directives are applied. The priority is used to sort the directives before their compile functions get called. Priority is defined as a number. Directives with greater numerical priority are compiled first. Pre-link functions are also run in priority order, but post-link functions are run in reverse order. The order of directives with the same priority is undefined. The default priority is
0
.
Angular 翻译库在 $translateProvider API 中有一个 directivePriority(priority)
函数,允许您将指令配置为 运行 的更高优先级,例如 101
.这应该让你的 translate
指令在插值之前变为 运行。