angular - Angular 6 的引导模式
问题描述
我有一个角度应用程序,我想使用引导模式作为确认框。我的确认框如下:
import { Component } from '@angular/core';
import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'ngbd-modal-confirm',
template: `
<div class="modal-header">
<h4 class="modal-title" id="modal-title">Profile deletion</h4>
<button type="button" class="close" aria-describedby="modal-title" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p><strong>Are you sure you want to delete <span class="text-primary">"John Doe"</span> profile?</strong></p>
<p>All information associated to this user profile will be permanently deleted.
<span class="text-danger">This operation can not be undone.</span>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary" (click)="modal.dismiss('cancel click')">Cancel</button>
<button type="button" class="btn btn-danger" (click)="modal.close('Ok click')">Ok</button>
</div>
`
})
export class NgbdModalConfirm {
constructor(public modal: NgbActiveModal) {}
}
我在一个类中使用这个确认框,如下所示:
export class NgbdModalFocus {
constructor(private _modalService: NgbModal) {}
open(name: string) {
this._modalService.open(NgbdModalConfirm);
}
}
我想如果用户按下确定按钮,然后在 NgbdModalFocus 内部触发一个事件来做某事。顺便说一句,我不确定正确的方法是触发事件还是其他任何东西。主要的是我希望通过单击确认框上的确定按钮在第二堂课内完成这项工作。
解决方案
将 ngb-bootstrap 导入 app.module.ts 很重要:
/* ngb bootstrap */
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
...
imports: [
BrowserModule.withServerTransition({ appId: 'ng-cli-universal' }),
HttpClientModule,
FormsModule,
AuthModule.forRoot(),
NgbModule.forRoot(),
RouterModule.forRoot([
{ path: '', component: HomeComponent, pathMatch: 'full' },
{ path: 'autologin', component: AutoLoginComponent },
{ path: 'counter', component: CounterComponent },
{ path: 'fetch-data', component: FetchDataComponent },
])
],
这是一个示例实现的链接: https ://www.thetechieshouse.com/angular-4-bootstrap-modal-popup/
推荐阅读
- ios - 斯威夫特:UISlider轨道的一侧不圆
- sql - 查询之间的区别
- python - Python 升级图像(没有外部库帮助)
- c# - 通过菜单c#打开和关闭表单
- python - TkInter 错误:没有显示名称和 $DISPLAY 环境变量
- android - 如何从在线下载视频并将其存储在本地设备上,然后使用视频播放器在 Flutter 应用程序上播放视频?
- c# - 是否使用 System.Security.Cryptography.RSACng 来签名和验证数据线程安全?
- python - 将表列和值转换为嵌套 JSON
- angular - Angular - 可安装性“未检测到匹配的服务人员”
- angular - 动态地图点数据,doc.getElementById('id1') 以角度返回 null