Bird
0
0

Which of the following correctly demonstrates how to create an Angular module using the @NgModule decorator?

easy📝 Syntax Q3 of 15
Angular - Modules
Which of the following correctly demonstrates how to create an Angular module using the @NgModule decorator?
A<pre>@Injectable() export class MyModule {}</pre>
B<pre>@Component({ selector: 'app-root' }) export class MyModule {}</pre>
C<pre>export class MyModule { declarations: [MyComponent]; imports: [BrowserModule]; }</pre>
D<pre>@NgModule({ declarations: [MyComponent], imports: [BrowserModule] }) export class MyModule {}</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Identify Angular module syntax

    The @NgModule decorator is used to define an Angular module.
  2. Step 2: Check the structure

    The correct syntax includes metadata properties like declarations and imports inside the decorator.
  3. Final Answer:

    @NgModule({ declarations: [MyComponent], imports: [BrowserModule] }) export class MyModule {}
    correctly shows the Angular module definition.
  4. Quick Check:

    Only @NgModule defines modules [OK]
Quick Trick: Use @NgModule decorator with metadata to define modules [OK]
Common Mistakes:
  • Confusing @Component with @NgModule
  • Defining module metadata outside decorator
  • Using @Injectable instead of @NgModule

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes