2013-12-20 18 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查找其註冊類型/值/工廠,並使用提供的實例(值)或創建新實例(類型)或使用工廠返回並注入它的結果。