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.


What annotation is used to define a module in Angular?

  1. @Component

  2. @Directive

  3. @NgModule

  4. @Service

The correct answer is: @NgModule

The annotation used to define a module in Angular is @NgModule. This decorator is essential for organizing an Angular application into cohesive blocks of functionality. It allows developers to group related components, directives, pipes, and services, thereby encapsulating specific functionalities and promoting modular design. The @NgModule decorator takes a metadata object that configures the module. This includes declarations, which define the components and directives that are part of the module, as well as imports, which allow the module to bring in functionality from other modules. Additionally, it can specify providers for services that are available to the components in the module and bootstrap information for the root module. In contrast, @Component is used to create components, @Directive is for custom directives allowing developers to extend HTML behavior, and @Service is intended for defining services that can be injected into components and other services. Each of these decorators serves a unique purpose within the Angular architecture, but @NgModule specifically relates to the definition and configuration of modules.