css - 使用组件作为内容自定义 ng-bootstrap 模态

标签 css angular bootstrap-4 ng-bootstrap

我一直在尝试使用作为内容传递的组件来自定义模式。但是,我似乎无法让它发挥作用。它只是显示了一个背景,模态框本身没有显示。看这个 fork 的 stackblitz代码以获取更多详细信息。

基本上我只需要自定义模态框的宽度。在指南中,它传递了内容模板引用,如本 section 中所述。 .但就我而言,我传递的不是 TemplateRef,而是一个组件。

最佳答案

删除 <ng-template let-modal> NgbdModalContent 的 wrapper (及其后半部分)的模板。

@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) {}
}

关于css - 使用组件作为内容自定义 ng-bootstrap 模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53049306/

相关文章:

css - 如何在 Ember 中使用 css 动画

javascript - Angular 5 - 如何在某些路由上加载某些 css 样式(引导 css 仅适用于管理路由)

javascript - 考虑到性能和广告显示,如何使用 React 和样式组件在 2 个响应式标题(移动和桌面)之间切换?

Javascript:将 CSS 样式属性插入数组

angular - 使用 Angular-CLI 6.1.2 创建新项目时出错

Angular 7 如何使用新的@aiStore

html - 在 ul 中使用绝对定位的子 div

jquery - 在 anchor 上应用默认焦点(来自 5 个 anchor 的列表)

有 Angular Material : How to set required validator as optional in reactive form

html - Bootstrap 图像缩略图大小不同