2013-12-20 19 views
3

我有一个组件需要从Dart代码访问其根元素。通过在SO上阅读Differences between Angular.js and Angular.dart?,并在AngularDart源代码中寻找,我发现我需要的是为构造函数提供显式类型的参数。如果其中一个参数的类型为dom.Element,则它将被Angular注入器引用到我的组件根目录。 (未能对构造函数的参数结果类型的异常NoSuchMethodError : method not found: 'simpleName'正从角内部深处泛起)我的代码现在看起来像这样:AngularDart依赖注入是如何工作的?

@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源代码中,喷油器的配置如何?

回答

1

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

你可以看看Angular.dart source - search for 'type(' like lib/core/module.dart

(请忽略结果,其中type不是函数名)

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