Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Latest commit

 

History

History
39 lines (32 loc) · 815 Bytes

prefer-on-push-cd-strategy.mdx

File metadata and controls

39 lines (32 loc) · 815 Bytes

import RuleDetails from '@site/src/components/RuleDetails';

Prefer setting changeDetection: ChangeDetectionStrategy.OnPush in Angular @Component annotations. OnPush strategy should be used as the default because using Default strategy leads to performance issues.

Example {#example}

❌ Bad:

@Component(
  selector: 'component-selector',
  templateUrl: 'component.html',
  styleUrls: ['component.css'],
  directives: <Object>[
    coreDirectives,
  ],
)
class Component {
}

✅ Good:

@Component(
  selector: 'component-selector',
  templateUrl: 'component.html',
  styleUrls: ['component.css'],
  changeDetection: ChangeDetectionStrategy.OnPush,
  directives: <Object>[
    coreDirectives,
  ],
)
class Component {
}