使用组件作为内容定制ng-boostrap模态

时间:2018-10-29 15:55:19

标签: css angular bootstrap-4 ng-bootstrap

我一直在尝试使用作为内容传递的组件来自定义模式。但是,我似乎无法使其工作。它只是显示背景,而模态本身未显示。观看此分叉的stackblitz代码以获取更多详细信息。

基本上,我只需要自定义模态的宽度。在该指南中,它通过了此section中所述的内容模板参考。但就我而言,我没有传递TemplateRef而是一个Component。

1 个答案:

答案 0 :(得分:1)

<ng-template let-modal>的模板中删除NgbdModalContent包装器(及其结尾的一半)。

@Component({
  selector: 'ngbd-modal-content',
  template: `
      <div class="modal-header">
        <h4 class="modal-title">Hi there!</h4>
        <button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <p>Hello, {{name}}!</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-outline-dark" (click)="activeModal.close('Close click')">Close</button>
      </div>
  `
})
export class NgbdModalContent {
  @Input() name;

  constructor(public activeModal: NgbActiveModal) {}
}