2017-03-27 12 views
1

DropDownListコンポーネントに配置されるカスタムディレクティブを作成しようとしています。ディレクティブのコンストラクタでは、ホストDropDownListコンポーネントのリファレンスを取得したいと考えています。私は、ドキュメントに何かを見つけることができませんでした角2の剣道UIディレクティブのアクセスコンポーネント

import { Directive, ElementRef } from '@angular/core'; 
 
import { DropDownListComponent } from '@progress/kendo-angular-dropdowns'; 
 

 
@Directive({ 
 
\t selector: '[trackDDLChanges]' 
 
}) 
 
export class TrackDDLChangesDirective { 
 
\t ddl: DropDownListComponent; 
 

 
\t constructor(elem: ElementRef) { 
 
\t \t this.ddl = elem.nativeElement; <-- how to get the reference of the component? 
 
\t \t 
 
\t } 
 
}

は、ここに私のコードです。 ElementRefは私にhtml要素を与えますが、対応するコンポーネントに変換する方法が見つかりません。

剣道の以前のバージョンでは、私たちは何ができる:

$(elem).data('kendoDropDownList')

は、ウィジェットへの参照を取得します。

このバージョンに似たようなものがありますか?

ありがとうございます。適切なタイプが定義されている場合

答えて

1

角度DIは、コンポーネントインスタンスを注入する。

@Directive({ 
    selector: '[custom-behavior]' 
}) 
export class CustomDirective { 
    constructor(ddl: DropDownListComponent) { 
    console.log('test', ddl); 
    } 
} 

http://plnkr.co/edit/V5jJASqJ7NxToXIerp5z?p=preview

+1

ブリリアント。ありがとう@ジョージK – dpdragnev

関連する問題