Challenge - 5 Problems
Angular Service CLI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate1:30remaining
What is the correct Angular CLI command to create a service named
user?Choose the exact Angular CLI command that generates a service named
user in the default folder.Attempts:
2 left
💡 Hint
The Angular CLI uses
generate or its shorthand g to create new files.✗ Incorrect
The correct command to create a service is ng generate service user. The other commands are invalid Angular CLI commands.
❓ component_behavior
intermediate1:30remaining
What will be the providedIn scope of a service created with
ng generate service user by default?After running
ng generate service user, what is the default providedIn value in the generated service's decorator?Attempts:
2 left
💡 Hint
Angular services are usually provided at the root level for app-wide singleton behavior.
✗ Incorrect
By default, Angular CLI adds providedIn: 'root' to the service decorator. This makes the service available app-wide as a singleton.
🔧 Debug
advanced1:30remaining
Why does this Angular CLI command fail?
ng generate serviceYou run
ng generate service without any name. What error will Angular CLI show?Attempts:
2 left
💡 Hint
The CLI needs a name to create a service file.
✗ Incorrect
The Angular CLI requires a service name argument. Running ng generate service alone causes an error about missing the required name argument.
❓ state_output
advanced2:00remaining
What files are created by
ng generate service auth?Select the exact files generated by Angular CLI when creating a service named
auth.Attempts:
2 left
💡 Hint
Angular CLI generates a TypeScript file and a test spec file for services.
✗ Incorrect
By default, Angular CLI creates two files: auth.service.ts and auth.service.spec.ts for the service and its tests.
🧠 Conceptual
expert2:00remaining
Which Angular CLI command creates a service in a specific folder
shared with the name logger?You want to create a service named
logger inside the src/app/shared folder using Angular CLI. Which command is correct?Attempts:
2 left
💡 Hint
Use the folder path before the service name separated by a slash.
✗ Incorrect
The correct syntax is ng generate service shared/logger. The CLI interprets the path before the slash as the folder and the last part as the service name.