2017-04-25 10 views
3

誰かが何かを言う前に、JqueryとAngular2を混ぜるのはベストプラクティスではないことに気付いています。しかし、私はJQueryに依存しているレイアウトマネージャ(黄金のレイアウト)を持っています。個々のタイルが作成されたら、チャート/テーブルで構成されるAngular 2コンポーネントをタイルに付けたいと思います。Angular 2 Componentを特定のDOMに追加する

私はAPIを使用してコンテナを簡単に取得できますが、jqueryの選択によるものです。それをViewContainerRefに変換するにはどうすればいいですか?

+0

ここで何かが役に立ちます:http://stackoverflow.com/questions/30623825/how-to-use-jquery-with-angular2 – DeborahK

答えて

0
export class ComponentService { 
    constructor(private componentFactoryResolver: 
     ComponentFactoryResolver, 
      private appRef: ApplicationRef, 
      private injector: Injector) { 
    } 

    create(component){ 
    // get factory and create component 
    let factory = this.componentFactoryResolver.resolveComponentFactory(component); 
    let ref = confirmDialogFactory.create(this.injector); 

    // set input prop 
    ref.instance.prop ='ABC'; 

    // attach to dom 
    document.querySelector('body') 
      .appendChild(ref.location.nativeElement); 

     // run change detection 
    this.appRef.attachView(ref.hostView); 
    ... 
    } 
関連する問題