我正在使用带有@ng-bootstrap 的Angular 2。我有一个这样的模态对话框:
<template #editDialog let-c="close" let-d="dismiss">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="d()">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">MyHeader</h4>
</div>
<div class="modal-body">
<div class="form">
<label class="form-label" for="myinput">Caption: </label>
<input class="form-control" type="text" id="myinput" [ngModel]="selected.Caption" />
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default" (click)="c('true')">OK</button>
<button class="btn btn-default" (click)="c('false')">Cancel</button>
</div>
</template>
我想重用模态对话框的框架,只想更改组件中的主体。它应该看起来像这样:
<my-modal>
<div class="form">
<label class="form-label" for="myinput">Caption: </label>
<input class="form-control" type="text" id="myinput" [ngModel]="selected.Caption" />
</div>
</my-modal>
谁能告诉我如何实现这一点,尤其是模型(selected.Caption)?我已经尝试了很多,但没有得到它的工作。
更新
清除:我想注入一些 HTML 标签,所以我得到了类似的东西:
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">{{title}}</h4>
</div>
<div class="modal-body">
<!-- MY CUSTOM HTML COMES HERE! -->
<!-- MAYBE WITH <ng-content></ng-content> -->
</div>
<div class="modal-footer">
<button class="btn btn-default" (click)="activeModal.close(true)">OK</button>
<button class="btn btn-default" ((click)="activeModal.close(false)">Abbrechen</button>
</div>
@pkozlowski.opensource 的答案基本上适用于打开和关闭模式。但我没有把我的身体放进去:
<my-modal>
<div class="form">
<label class="form-label" for="myinput">Caption: </label>
<input class="form-control" type="text" id="myinput" [ngModel]="selected.Caption" />
</div>
</my-modal>