【发布时间】:2017-08-06 13:40:03
【问题描述】:
我正在使用 Angular 2.4.9 并实现了一个自定义错误处理程序,它只捕获所有错误并导航到错误路由以显示消息。
我有一个切换按钮来显示/隐藏绑定到布尔值的详细消息(也尝试了对象内的布尔值,即 object.showError)如果我捕获 Http 错误并自己抛出错误,所有工作正常。但是,如果我遇到诸如 ViewWrappedError 之类的 Angular 错误,则数据绑定将拒绝工作。 (单击) evets 仍然有效,布尔值从 true 切换为 false,只是更改不会反映在页面上。
我是否缺少一些东西来让它工作?
import { Component } from '@angular/core';
import { ErrorService } from './error.service';
import { Error } from './index';
@Component({
moduleId: module.id,
selector: 'error',
templateUrl: 'error.component.html',
styleUrls: ['error.component.css']
})
export class ErrorComponent {
public error: Error;
public showDetailedError: boolean;
constructor(private errorService: ErrorService) {
this.showDetailedError = false;
this.error = this.errorService.getError();
}
}
HTML 模板
<div class="error-container">
<h1>Sorry, something went wrong.</h1>
<p class="error-message">An error occurred while processing your request. Details on this error can be found below.</p>
</div>
<p *ngIf="!showDetailedError" (click)="showDetailedError = !showDetailedError" class="info-icon">Click for detailed description</p>
</div>
【问题讨论】:
标签: angular typescript data-binding error-handling