0
0
Angularframework~5 mins

Pure vs impure pipes in Angular - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a pure pipe in Angular?
A pure pipe is a pipe that Angular executes only when it detects a pure change to the input value. Pure changes include changes to primitive types or object references. Pure pipes improve performance by avoiding unnecessary recalculations.
Click to reveal answer
beginner
What is an impure pipe in Angular?
An impure pipe is a pipe that Angular executes on every change detection cycle, regardless of whether the input value changed. This is useful when the pipe depends on mutable objects or external state.
Click to reveal answer
intermediate
How do you declare a pipe as impure in Angular?
You declare a pipe as impure by setting the 'pure' property to false in the @Pipe decorator, like this: @Pipe({name: 'myPipe', pure: false}).
Click to reveal answer
intermediate
Why should you avoid using impure pipes when possible?
Impure pipes run on every change detection cycle, which can hurt performance. Using pure pipes when possible helps Angular skip unnecessary work and keeps apps fast.
Click to reveal answer
advanced
Give an example scenario where an impure pipe is necessary.
When a pipe transforms data from a mutable object like an array that changes internally (e.g., items added or removed without changing the array reference), an impure pipe ensures the view updates correctly.
Click to reveal answer
When does Angular execute a pure pipe?
AWhen the user clicks a button
BOn every change detection cycle
COnly when the input reference or primitive value changes
DOnly once when the component loads
How do you mark a pipe as impure in Angular?
AUse @ImpurePipe decorator
BSet pure: false in the @Pipe decorator
CSet pure: true in the @Pipe decorator
DNo special setting needed
What is a downside of using impure pipes?
AThey run on every change detection cycle, which can reduce performance
BThey never update the view
CThey only work with primitive values
DThey require manual triggering
Which pipe type is best for transforming immutable data?
APure pipe
BImpure pipe
CAsync pipe
DNo pipe
If you have an array that changes internally but keeps the same reference, which pipe should you use?
APure pipe
BNo pipe
CAsync pipe
DImpure pipe
Explain the difference between pure and impure pipes in Angular and when to use each.
Think about how Angular detects changes and when it runs pipes.
You got /4 concepts.
    Describe how to declare an impure pipe and why you might need one.
    Focus on the decorator setting and use case.
    You got /4 concepts.