3

我有一个组件需要从 Dart 代码中访问其根元素。通过阅读Angular.js 和 Angular.dart 之间的差异?在 SO 上并在 AngularDart 源代码中四处寻找我发现我需要的是提供一个带有显式类型参数的构造函数。如果其中一个参数具有 type dom.Element,它将由 Angular 注入器提供对我的组件根目录的引用。(在构造函数参数上没有类型会导致NoSuchMethodError : method not found: 'simpleName'从 Angular 内部深处抛出异常。)我的代码现在看起来像这样:

@ng.NgComponent (
    selector: 'math',
    templateUrl: 'packages/embarassing_name_of_my_package/math/math_component.html',
    publishAs: 'ctrl'
)
class MathComponent {
  ng.Scope _scope;
  dom.Element _element;
  ng.NgModel _ngModel;
  ng.NodeAttrs _attrs;

  MathComponent(this._scope, this._element, this._ngModel, this._attrs);

  …
}

ngdom存在

import 'package:angular/angular.dart' as ng;
import 'dart:html' as dom;

现在的问题。我如何最好地发现喷油器反应的那些特殊类型?

此外,我想知道:它是否记录在某处?在哪里?如果不是,那么在 AngularDart 源中,注入器在哪里被配置为像这样运行?

4

1 回答 1

1

使用Module.type()方法(或工厂、值)注册类。

您可以查看Angular.dart 源代码 - 搜索 'type(' like lib/core/module.dart

(请忽略type不是函数名的结果)

当 Angular 调用的构造函数或方法需要参数时,DI 会查找其注册的类型/值/工厂并使用提供的实例(值)或创建新的实例(类型)或使用工厂返回的结果并注入它。

于 2013-12-21T10:05:35.240 回答