繁体   English   中英

Angular NGX 引导模式 - 缺少内容

[英]Angular NGX Bootstrap Modal - content is missing

这是这个问题的后续: How to show a bootstrap modal via an angular service

我的模态现在正在显示,但没有内容。

在此处输入图像描述

模态的结构是我想要的,背景也显示出来了,但没有内容。

这是我的代码:

@Component({
  selector: 'error-banner',
  templateUrl: './error-banner.component.html',
  styleUrls: ['./error-banner.component.scss']
})
export class ErrorBannerComponent {
  title: string;
  buttonTitle = Title.Ok;
  message: string;
  type: 'warning';
  button: Button;
  @ViewChild('template', { static: false }) template;

  protected modalRef: BsModalRef;

  constructor(private modalService: BsModalService) {}

  public show(title: string, message: string) {
    const initialState = {
      title,
      message
    };
    this.modalRef = this.modalService.show(
      this.template,
      Object.assign({}, { initialState, class: `modal-banner ${this.type}`})
    );
    // out of despair
    this.title = title;
    this.message = message;
    this.modalRef.content = this.template;
    this.modalRef.setClass(`modal-banner ${this.type}`);
  }

  hide() {
    if (this.modalRef) {
      this.modalRef.hide();
    }
  }
}

BsModalService 在我的 Global-Modul 中提供。

最后,像这样在我的 Errorhandler 中调用 Modal。

@Injectable()
export class GlobalErrorHandler implements ErrorHandler {

  errorBanner;

  constructor(private injector: Injector) {}

  handleError(error: Error | HttpErrorResponse) {

    const errorService = this.injector.get(ErrorService);
    const logger = this.injector.get(LoggingService);
    const modalService = this.injector.get(BsModalService);
    this.errorBanner = new ErrorBannerComponent(modalService);

    let message;
    let stackTrace;

    if (error instanceof HttpErrorResponse) {
      message = errorService.getServerMessage(error);
      stackTrace = errorService.getServerStack(error);
      this.errorBanner.show(Title.ServerError, message);
    } else {
      message = errorService.getClientMessage(error);
      stackTrace = errorService.getClientStack(error);
      this.errorBanner.show(Title.ClientError, message);
    }

    logger.logError(message, stackTrace);
  }
}

我已经尝试过使用单独的服务,但结果是一样的 - 我在这里错过了什么?

这篇文章并按照确切的说明帮助我解决了这个问题:

使用 NGX Bootstrap-Modals 单独的组件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM