user3887366
user3887366

Reputation: 2594

Angular update property with OnPush change detection

With this code using changeDetection: ChangeDetectionStrategy.Default

export class HomePageComponent {
  constructor(
    private i18nService: I18nService
  ) {}
  get language(): string {
    return this.i18nService.language;
  }
}

angular update the view but using changeDetection: ChangeDetectionStrategy.OnPush,

it doesn't so the question is:

How can update the view using OnPush?

Upvotes: 0

Views: 1108

Answers (1)

Dennis
Dennis

Reputation: 391

OnPush will only run change detection once (on creation). And Angular then only triggers change detection when a reference of an @Input() property changes (or if an Event handler of your component gets invoked). In your component I see no @Input() statements at all.

You can manually run change detection by injecting ChangeDetectorRef into your component and calling appropriate methods on it.

Upvotes: 1

Related Questions