detach method
Detaches the component from the change detection hierarchy.
A component whose change detector has been detached will be skipped during change detection until reattach is called. This strategy could be used for specific optimizations around components that are not visible to the user (such as modals or popups) but are loaded.
NOTE: Lifecycle events (such as ngOnInit
, ngAfterChanges
, and so
on) are still called if the component has been detached. We may consider
changing this behavior in the future: b/129780288.
In most cases simply using ChangeDetectionStrategy.onPush
and calling
markForCheck is preferred as it provides the same contract around not
checking a component until it is dirtied.
WARNING: This API should be considered rather rare. Strongly
consider reaching out if you have a bug or performance issue that leads
to using detach over ChangeDetectionStrategy.onPush
/ markForCheck.
Implementation
@Deprecated('Use "changeDetection: ChangeDetectionStrategy.onPush" instead')
void detach() {
detachDeprecated();
}