Marks all ChangeDetectionStrategy#OnPush
ancestors as to be checked.
<!-- TODO: Add a link to a chapter on OnPush components -->
Example
@Component(
selector: 'cmp',
changeDetection: ChangeDetectionStrategy.OnPush,
template: 'Number of ticks: {{numberOfTicks}}')
class Cmp {
int numberOfTicks = 0;
Cmp(ChangeDetectorRef ref) {
new Timer.periodic(const Duration(seconds: 1), () {
numberOfTicks++;
// the following is required, otherwise the view will not be updated
ref.markForCheck();
});
}
}
@Component(
selector: 'app',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '''
<cmp><cmp>
''',
directives: const [Cmp])
class App {}
void main() {
bootstrap(App);
}
Source
void markForCheck();