[ Web Proxy ]
URL:
Viewing: https://angular.dev/api/core/effect [Back]  [Original]

effect Angular Skip to main content
menu
close
more_horiz
menuAPI
@angular/core

effect

function
stablesince v20.0

Registers an "effect" that will be scheduled & executed whenever the signals that it reads changes.

Effects

On this page

    arrow_upward_alt Back to the top

    API

    function effect(
      effectFn: (onCleanup: EffectCleanupRegisterFn) => void,
      options?: CreateEffectOptions | undefined,
    ): EffectRef;
    @parameffectFn(onCleanup: EffectCleanupRegisterFn) => void
    @paramoptionsCreateEffectOptions | undefined
    @returnsEffectRef

    Description

    Registers an "effect" that will be scheduled & executed whenever the signals that it reads changes.

    Angular has two different kinds of effect: component effects and root effects. Component effects are created when effect() is called from a component, directive, or within a service of a component/directive. Root effects are created when effect() is called from outside the component tree, such as in a root service.

    The two effect types differ in their timing. Component effects run as a component lifecycle event during Angular's synchronization (change detection) process, and can safely read input signals or create/destroy views that depend on component state. Root effects run as microtasks and have no connection to the component tree or change detection.

    effect() must be run in injection context, unless the injector option is manually specified.

    Jump to details

    Web Proxy Viewer  |  New URL  |  Original Page