小编Ber*_* Ng的帖子

Angular 2在抛出异常后不会更新视图

当Angular 2的异常处理程序捕获到异常时,UI不再"更新".我在这里有一个非常简单的例子:

https://plnkr.co/edit/iHDYpZ3fDlO6bhOtlTbQ

import { Component, ExceptionHandler, Injectable, OnInit, provide } from '@angular/core';
import { bootstrap } from '@angular/platform-browser-dynamic';
import { Subject } from 'rxjs/Subject'

export interface Alert {
  message: string;
}

@Component({
  selector: 'my-app',
  template : `
  <h3>Parent</h3>
  {{aValue}}
  <br/>
  <br/>
  <button (click)='doIt()'>do it</button>
  <br/>
  <br/>
  <button (click)='breakIt()'>break it</button>
  `
})

export class App implements OnInit {
  private aValue: boolean = true
  constructor() { }
  
  alerts: Alert[] = [];
  
  doIt(){
    console.log('Doing It')
    this.aValue = !this.aValue
  }
  
  breakIt(){
    console.log('Breaking It') …
Run Code Online (Sandbox Code Playgroud)

exception typescript angular

11
推荐指数
2
解决办法
2700
查看次数

标签 统计

angular ×1

exception ×1

typescript ×1