简体   繁体   English

Angular NGX 引导模式 - 缺少内容

[英]Angular NGX Bootstrap Modal - content is missing

This is a follow-up of this question: How to show a bootstrap modal via an angular service这是这个问题的后续: How to show a bootstrap modal via an angular service

My modal is now showing but there is no content to it.我的模态现在正在显示,但没有内容。

在此处输入图像描述

The structure of the modal is how I intented it to be, the backdrop is shown aswell but there is no content to it.模态的结构是我想要的,背景也显示出来了,但没有内容。

Here is my code:这是我的代码:

@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();
    }
  }
}

The BsModalService is provided in my Global-Modul. BsModalService 在我的 Global-Modul 中提供。

Finally the Modal is called in my Errorhandler like this.最后,像这样在我的 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);
  }
}

I've tried it with a seperated Service, but the results are the same - what am I missing here?我已经尝试过使用单独的服务,但结果是一样的 - 我在这里错过了什么?

This article and following the exact instructions helped me to solve the issue:这篇文章并按照确切的说明帮助我解决了这个问题:

Using NGX Bootstrap-Modals seperate Component 使用 NGX Bootstrap-Modals 单独的组件

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

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