Angular:OnPush ChangeDetectionStrategy 对仅具有原始值的组件的好处

Angular: OnPush ChangeDetectionStrategy benefit for components with only primitive values

如果组件只有原始值绑定但使用 ChangeDetectionStrategy.OnPush,是否有任何性能优势?或者在这种情况下可能存在一些缺点?

示例用例:

@Component({
  selector: 'my-component',
  templateUrl: './my-component.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class MyComponent {
  @Input() title: string;
  @Input() count: number;
}

是的。因为其他变化检测器触发器(例如,组件中的任何 DOM 事件)不会被 ChangeDetectionStrategy.OnPush

触发