Skip to content

Instantly share code, notes, and snippets.

@robertdempsey
Created May 7, 2020 10:56
Show Gist options
  • Save robertdempsey/a87b411d9c7be0164908ef5a9642e298 to your computer and use it in GitHub Desktop.
Save robertdempsey/a87b411d9c7be0164908ef5a9642e298 to your computer and use it in GitHub Desktop.
Triggers change detection with OnPush strategy even if it is manually triggered from outside.
import { Component, EventEmitter, Input, Output, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'display',
templateUrl: './display.component.html',
styleUrls: ['./display.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DisplayComponent {
constructor(private changeDetectorRef: ChangeDetectorRef) {
}
@Input() set dynamicInputUpdateCount(inputData: string) {
this._dynamicInputUpdateCount = inputData;
this.changeDetectorRef.detectChanges();
}
@Input() componentDescription: string;
@Input() inputData: string;
_dynamicInputUpdateCount: string;
@Output() dataUpdated = new EventEmitter<string>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment