Recall & Review
beginner
What is the Angular CLI command to create a new service?
Use
ng generate service service-name or the shortcut ng g s service-name to create a new service.Click to reveal answer
beginner
Where does Angular CLI place the new service file by default?
By default, the service is created inside the
src/app folder or the current directory where the command is run.Click to reveal answer
beginner
What file extensions are created when you generate a service with Angular CLI?
Angular CLI creates two files:
service-name.service.ts (the service code) and service-name.service.spec.ts (the test file).Click to reveal answer
intermediate
How does Angular CLI register the new service for dependency injection?
The generated service class is decorated with <code>@Injectable({ providedIn: 'root' })</code>, which makes it available app-wide without manual registration.Click to reveal answer
intermediate
Can you specify a different path or module when generating a service with Angular CLI?
Yes, you can specify a path like
ng g s folder/service-name or use flags like --module to provide the module for service registration.Click to reveal answer
Which Angular CLI command creates a new service named
data?✗ Incorrect
The correct command is
ng generate service data or ng g s data.What decorator does Angular CLI add to a generated service to enable dependency injection?
✗ Incorrect
Angular services use the
@Injectable decorator to support dependency injection.Where is the new service file created by default when running Angular CLI service generation?
✗ Incorrect
By default, Angular CLI creates the service inside the
src/app folder.What is the purpose of the
--module flag when generating a service?✗ Incorrect
The
--module flag tells Angular CLI which module to register the service with.What files are created when you generate a service using Angular CLI?
✗ Incorrect
Angular CLI creates the service file and a matching test file with
.spec.ts extension.Explain how to create a new Angular service using the CLI and how it is made available for use in the app.
Think about the command, files created, and dependency injection setup.
You got /4 concepts.
Describe how you can customize the location or module when generating a service with Angular CLI.
Consider command options and file placement.
You got /4 concepts.