Triggering change detection manually in Angular

后端 未结 5 860
滥情空心
滥情空心 2020-11-21 11:47

I\'m writing an Angular component that has a property Mode(): string.

I would like to be able to set this property programmatically not in response to a

5条回答
  •  别跟我提以往
    2020-11-21 11:56

    I used accepted answer reference and would like to put an example, since Angular 2 documentation is very very hard to read, I hope this is easier:

    1. Import NgZone:

      import { Component, NgZone } from '@angular/core';
      
    2. Add it to your class constructor

      constructor(public zone: NgZone, ...args){}
      
    3. Run code with zone.run:

      this.zone.run(() => this.donations = donations)
      

提交回复
热议问题