这是我的模板的一部分:
<!-- This is the one I want! -->
<label>{{l10n('hallo') | translate}}</label>
如果我的组件有一个函数 l10n 调用 l10n 函数没有问题
<label>{{cmp.l10n('hallo') | translate}}</label>
但这不是我想要的——如果可能的话,我想要
l10n(<string>)
,不知何故这个模板的全局函数......在 AngularJS 中,为了实现一些链接,他们向 Controller-Scope 添加了一个函数:https://stackoverflow.com/a/12466994/504184
我的问题是我没有 Controller - 我在一个组件中......
第二件事是 AngularDart 中的 Scope 与 AngularJS 中的 Scope 完全不同......
最佳答案
您可以在组件中注入(inject) Scope 并添加函数。
@Component(selector: 'my-comp')
class Comp {
Comp(Scope scope) {
scope.context['l10n'] = (str) => "Boo[$str]";
}
}
但是,我们正在考虑在即将发布的 AngularDart 版本中删除此功能。
关于dart - 如何基于组件调用模板中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25285341/