Prepare for Angular Interviews with real-life questions. Utilize quizzes and examples to deepen understanding and enhance your skills. Gear up to ace your interview!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which decorator is used to create a custom pipe in Angular?

  1. @Component

  2. @Injectable

  3. @Pipe

  4. @Directive

The correct answer is: @Pipe

To create a custom pipe in Angular, the appropriate decorator to use is the @Pipe decorator. This decorator allows you to define the metadata for the pipe, including its name, which is how the pipe can be referenced within templates. By using @Pipe, you enable Angular to understand the functionality of your custom transformation logic that the pipe provides, ultimately allowing you to manipulate data displayed in your templates effectively. When defining a pipe, you'll typically implement the PipeTransform interface, which requires you to define the transform method that contains the logic for how input values should be transformed. This structure is pivotal for ensuring that Angular can use your custom pipe seamlessly during data binding in Angular's template syntax. While other decorators like @Component and @Directive serve their respective purposes in defining components and directives, they do not provide the specific functionality associated with transforming data, which is the central role of a pipe. @Injectable is used for services and dependencies, further distinguishing it from the pipe functionality. Thus, @Pipe is uniquely positioned to facilitate custom data transformation within Angular applications.