This is a simple Angular module. It declares two components: AppComponent and HelloComponent. It imports BrowserModule to run in a browser. It exports HelloComponent so other modules can use it. The app starts with AppComponent.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MyComponent } from './my.component';
@NgModule({
declarations: [],
imports: [BrowserModule, MyComponent],
exports: [MyComponent]
})
export class AppModule {}
medium
A. exports cannot include components
B. BrowserModule cannot be imported
C. MyComponent should be in providers
D. MyComponent should be in declarations, not imports
Solution
Step 1: Identify where components belong
Components like MyComponent must be listed in declarations, not imports.
Step 2: Check imports and exports usage
Modules go in imports, components go in declarations. Exporting components is allowed.
Final Answer:
MyComponent should be in declarations, not imports -> Option D
Quick Check:
Components belong in declarations [OK]
Hint: Components go in declarations, modules in imports [OK]
Common Mistakes:
Putting components inside imports
Thinking exports can't include components
Confusing providers with declarations
5. You have two Angular modules: SharedModule declares and exports a component ButtonComponent. You want to use ButtonComponent inside FeatureModule. Which is the correct way to set this up?
hard
A. Import SharedModule in FeatureModule without declaring ButtonComponent again
B. Import SharedModule in FeatureModule and add ButtonComponent to declarations in FeatureModule
C. Add ButtonComponent to declarations in FeatureModule only
D. Export FeatureModule from SharedModule
Solution
Step 1: Understand exports and imports
SharedModule exports ButtonComponent, so importing SharedModule in FeatureModule makes ButtonComponent available.
Step 2: Avoid redeclaring exported components
Do not redeclare ButtonComponent in FeatureModule; just import SharedModule.
Final Answer:
Import SharedModule in FeatureModule without declaring ButtonComponent again -> Option A
Quick Check:
Import module exporting component, no redeclaration needed [OK]
Hint: Import module exporting component, no redeclare [OK]
Common Mistakes:
Redeclaring exported components in importing module
Not importing the module that exports the component
Trying to export the importing module instead
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.