effect()

noun

say it: “ih-FEKT” /ɪˈfɛkt/

An Angular function that runs code again whenever the signals it reads change.

What does effect() do?

effect() runs code whenever the signals it reads change. Use it for side effects like saving to local storage or logging, not for calculating values.

constructor() {
  effect(() => localStorage.setItem('theme', this.theme()));
}

In a sentence

  • “An effect saves the cart to local storage every time it changes.”

Level: Journeyman · More Angular terms at this level

Updated