我在angular中创建了一个错误处理程序,我想访问一个模态组件(在appmodule中注册)并在其中显示错误。我是棱角分明的新手,所以我无法弄清楚如何访问它。任何帮助,将不胜感激。 错误处理程序
export class GlobalErrorHandler implements ErrorHandler{
handleError(error){
alert(error);
console.log("handeled by GlobalErrorHandler")
console.log("error",error);
console.log("******************");
//instead of logging to the console, i would like to call globalModal component and show the error in a popup
}
}
全球模式html
<div bsModal #globalModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-success" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{_modalTitle|translate}}</h4>
<button type="button" class="close" (click)="globalModal.hide()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>{{_modalBody|translate}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="globalModal.hide()">Kapat</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
全球模式
@Component({
selector:'GlobalModal',
templateUrl: 'globalModal.component.html'
})
export class GlobalModalComponent {
@ViewChild('globalModal') globalModalElement:ModalDirective
_modalTitle:string;
_modalBody:string;
show(modalTitle,modalBody){
this._modalTitle = modalTitle;
this._modalBody = modalBody;
this.globalModalElement.show();
}
}