【发布时间】:2017-05-12 18:15:23
【问题描述】:
我正在开发带有模态对话框的 Angular 2 + TypeScript 应用程序。
我有主要的模态组件:
<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 编译成一个视图? 这样做的最佳方法是什么?我应该使用与模板表达式不同的东西吗?
【问题讨论】:
-
使用
@Input和@Output -
我怎样才能得到其他组件的html?请给我更多细节。
-
@echonax 它帮助了我
-
@A.Gladkiy Cool :-)
标签: angular typescript