How do you manage application state in AngularJS?
Instruction: Discuss strategies for managing state across different parts of an AngularJS application.
Context: This question explores the candidate's expertise in maintaining coherence and consistency of data throughout the application lifecycle.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Classify state by ownership and lifetime. Keep transient input/view state in the relevant controller or component, shared client state behind an injected service interface, shareable navigation state in the URL where suitable, and authoritative durable state on the server.
An AngularJS service instance is shared within its injector. It can coordinate a cached user profile or selected workspace, but separate tabs/injectors do not automatically share it, and a reload loses ordinary in-memory state...