dart - 如何基于组件调用模板中的函数?

标签 dart angular-dart

这是我的模板的一部分:

<!-- 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/

相关文章:

flutter - 如何将小部件放置在具有成比例大小和位置的小部件上方

dart - 如何正确启用/禁用 Flutter 的 Button

angular - Dart Angular 形成原始/脏动态

android - flutter 错误 : No named parameter with the name 'displayLarge'

flutter - 用=> 启动flutter 时如何调用多条语句?

dart - 角 2 Dart : How to bind events correctly to dynamically generated HTML (Removing disallowed attribute <DIV (click) ="...">)?

dart - 使用 Angular Dart 中的日志记录包的记录器服务

constructor - 构造函数中的 future 不起作用

dart - 用 Dart 模拟 - 如何测试作为参数传递的函数是否被调用?

angularjs - Dart 中的手动注入(inject)