我正在使用Angular 2.4.9並實現了一個自定義錯誤處理程序,它只捕獲所有錯誤並導航到錯誤路徑以顯示消息。使用自定義錯誤處理程序捕獲Javascript錯誤後Angular/Angular2數據綁定不工作
我有一個切換按鈕來顯示/隱藏綁定到一個布爾值的詳細消息(也嘗試了一個對象內的布爾值,即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>
爲我工作。將ApplicationRef添加到我的組件中,並在切換我的詳細錯誤時手動觸發更改檢測 –
感謝您的反饋 - 很好的瞭解。 –