angular 2-ngx引导在ajax调用上显示错误/警报/确认模式
我试图根据从ajax调用中得到的结果显示error/confirm/alert的modals 具有Ajax调用的组件-angular 2-ngx引导在ajax调用上显示错误/警报/确认模式,angular,modal-dialog,bootstrap-modal,ngx-bootstrap,Angular,Modal Dialog,Bootstrap Modal,Ngx Bootstrap,我试图根据从ajax调用中得到的结果显示error/confirm/alert的modals 具有Ajax调用的组件- ngOnInit() { this.initializeValues(); } initializeValues = function () { this._dataService.post("getInfoByUser", request, null).subscribe(data => {...}, error => {
ngOnInit() {
this.initializeValues();
}
initializeValues = function () {
this._dataService.post("getInfoByUser", request, null).subscribe(data =>
{...}, error => {
this._modalService.showError(Constants.TECH_EXCEPTION);
});
}
联运服务-
export class ModalService {
_pbModal: PubSubService = this.pubSubServiceModal;
constructor( @Inject(PubSubService) private pubSubServiceModal){
pubSubServiceModal.subjects = new Map<string, Subject<Modal>>();
}
showError(msg: string){
var modal = new Modal(Constants.ERROR,msg);
var data = { key: "showModal", value: modal };
this._pbModal.publish(data);
}
showAlert(msg: string){}
...
模态组件HTML-
<div id="modalDialog001-alert" class="modal fade" bsModal #appModal="bs-modal" [config]="{backdrop: ''}" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
<div class="modal-dialog" style="top:10%">
<div class="modal-content">
<div class="modal-header padding-5">
<button type="button" class="close" aria-label="Close" (click)="close()"><span aria-hidden="true">×</span></button>
<h3 class="modal-title">Sample Modal</h3>
</div>
<div class="modal-body">
<ng-content select=".modal-body"> </ng-content>
</div>
<div class="modal-footer" style="text-align:right">
<button type="button" class="btn btn-primary" (click)="confirmClick()"><i class="glyphicon glyphicon-ok"> Ok</i></button>
<button *ngIf="showConfirm" class="btn btn-default" (click)="close()" type="button">Cancel</button>
</div>
</div>
AppComponent HTML-
<app-modal>
<div class="modal-body">
<span class="glyphicon sb-alert-icon" [ngClass]="{ 'glyphicon-remove-sign text-danger': (type == error),'glyphicon glyphicon-alert text-warning': (type == alert) }" >{{msg}}</span>
</div>
</app-modal>
试图在appcomponent的ngAfterViewInit()中添加此行,但无效。请让我知道在我的案例中如何从Appcomponent调用Modalcomponent的方法
更新
appcomponent.html中的以下行导致了问题-
<app-modal>
我添加了以下内容并显示了modal-
<app-modal #appModal>
但是,我看到glyphicon css没有正确渲染
我可以让它适用于警报、错误、信息的模态(尽管有CSS问题)。但对于“确认”模式,我需要同时显示OK和Cancel按钮,这是我之前使用*ngIf所做的。既然我分别呈现了主体内容,那么如何在页脚中单独显示“确认”模式的dsiplay按钮呢?看起来我需要更改当前的操作方式,但不确定如何更改。您是否在模式组件.ts中使用了
选择器:“应用模式”
?如果是,则应使用:@ViewChild('app-modal')appModal:ModalComponent。试一试在模态组件.ts中是否使用了选择器:“应用模态”
?如果是,则应使用:@ViewChild('app-modal')appModal:ModalComponent。试试看
this.appModal.showModal(modal);
<app-modal>
<app-modal #appModal>