私はモーダルダイアログでAngular 2 + TypeScriptアプリを開発しています。個別のコンポーネントからモーダルダイアログを結合(コンパイル)する方法角2を動的に使用しますか?
Iは主モーダル成分を有する:
<div class="modal">
<div class="header">{{title}}</div>
<div class="body">{{body}}</div>
<div class="footer">{{footer}}</div>
</div>
{{title}}
- テキスト、{{body}}
と{{footer}}
- HTMLの異なるコンポーネントからです。
とモーダルダイアログを開くには、ボタンを含むコンポーネントで
私はこれを持っている:import { Component } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ModalComponent } from './modal.component';
import { BodyOneComponent } from './body/body-one.component';
import { FooterOneComponent } from './footer/footer-one.component';
@Component({
selector: 'ac-parent',
templateUrl: './app/parent.component.html'
})
export class ParentComponent {
constructor(private modalService: NgbModal) { }
openModal() {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.title = "Modal title";
modalRef.componentInstance.body = "get html from BodyOneComponent somehow";
modalRef.componentInstance.footer = "get html from FooterOneComponent somehow";
}
}
だから、私の問題は、私は、他のコンポーネントからコンポーネントのHTMLコンテンツを取得する方法ですか?そして、それらのhtmlを1つのビューにコンパイルするにはどうすればいいですか? これを実行する最良の方法は何ですか?私はテンプレート表現とは何か違うものを使うべきですか?
「@ Input」と「@ Output」を使用 – anshuVersatile
他のコンポーネントのHTMLをどのように取得できますか?詳細を教えてください。 –
これをチェック:http://stackoverflow.com/questions/36566698/how-to-dynamically-create-bootstrap-modals-as-angular2-components – echonax