【问题标题】:ng-bootstrap modal: open it via typescriptng-bootstrap modal:通过打字稿打开它
【发布时间】:2018-03-09 23:25:45
【问题描述】:

我遇到了问题,我想帮助我从组件中打开一个模式。 我想在表单中验证用户后打开模式。

.component.html

<ng-template #modalExample let-c="close" let-d="dismiss">
/** Modal body **/
</ng-template>

<form (ngSubmit)="f.form.valid && signin()" #f="ngForm" class="">
/** Buttons, labels, buttons **/ 
</form>

.component.ts

signin() { 
/**Calling backend**/ 
this.modalService( *REFERENCE TO MODAL HERE* )  
}

我试过了

@ViewChild('modalExample') modalExample: ElementRef
this.modalService.open(this.modalExample);

【问题讨论】:

    标签: html angular modal-dialog frontend ng-bootstrap


    【解决方案1】:

    open 方法期望组件或模板引用正常工作,ViewChild 默认为您提供 TemplateRef。要解决此问题,请将您的 ViewChild 声明更改为:

    @ViewChild('modalExample', {read: TemplateRef}) modalExample: TemplateRef<any>;
    

    当您想打开模式时,将其传递给this.modalService.open(this.modalExample),这应该可以工作。

    Bootstrap site 有各种示例,您可以查看如何打开模式。

    【讨论】:

    • 它工作得很好,但我在控制台中收到一个异常:“ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it is checked. Previous value: 'ng-untouched: true'. Current value: 'ng-untouched : 错误的'。”我能做什么?
    猜你喜欢
    • 2018-10-17
    • 2019-07-12
    • 2020-01-21
    • 2019-02-09
    • 1970-01-01
    • 2013-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多