4 views
How do pure and impure pipes detect updates to input data?
Asked at
AI answer
In Angular, a pure pipe (the default) is recalculated when a primitive input changes, when the reference to an object/array passed to the pipe changes, or when its arguments change. Changes made to an object “in place” are usually not detected: you need to create a new reference. An impure pipe is checked during every change detection cycle, so it can noticeably affect performance; use it only when necessary.
items = [...items, newItem]; // new reference — the pure pipe will detect the change
Also asked at НПП Баум
- Tell me about the Event Loop in JavaScript: what does it consist of and in what order are synchronous code, microtasks, and macrotasks executed?
- Briefly tell us about yourself: what should we know about you?
- Briefly tell us about yourself and your work experience.
- What is a generic in TypeScript? Provide an example of its application.
- In which direction would you like to develop in the future?
Similar questions
- What counts as a value change for a pure pipe—for primitives, objects, and arrays?
- What happens if a mutation is not a pure function and has side effects?
- How does Angular’s Change Detection mechanism work, and how are changes tracked?
- How does Angular update data when using Zone.js and Change Detection?
- What are the two main types of pipes in Angular? How do they differ?