ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
一:所有弹窗尽量以组件的形式编写 二:弹窗全部使用封装的 `modalHelper` ~~~ modalHelper类提供两个方法创建弹窗: 1.create (点击遮罩区可以关闭) 2.createStatic (点击遮罩区不可以关闭) this.modalHelper.create(FormEditComponent, { i }, { size: 'lg' }).subscribe(res => this.load()); 参数一:component组件 参数二:传递给组件的参数 参数三:扩展参数,扩展参数是一个对象 扩展参数: {size:'lg',modalOptions:{nz-modal对话框原始参数},includeTabs:false(是否包裹标签页)} ~~~ 三:交互 1.数据交互 关闭弹窗提供了两种方法 一:`this.modal.close(res);` 二:`this.modal.destroy(res);` 这两种方法都提供了一个可当作回调的`Observable` ,当调用关闭方法时可传递一个数据,推送到`Observable`对象中,然后就可以在`subscribe`中优雅的处理回调。 ``` this.modalHelper.create(ServiceComponent).subscribe(res => { //处理回调,回调参数即是传递的数据 this.service.show = true; this.service.name = res.addr; this.service.id = res.id; this.changeRef.markForCheck(); //触发变量检测 }); ``` 2.自定义弹窗头部 ``` <div class="modal-header"> <div class="modal-title">标题</div> </div> ``` 3.自定义弹窗底部 ``` <div class="modal-footer"> <button nz-button type="button" (click)="close()">关闭</button> <button nz-button type="submit" [nzType]="'primary'" (click)="save(sf.value)" [disabled]="!sf.valid" [nzLoading]="http.loading" > 保存 </button> </div> ```