0
0
Angularframework~5 mins

Creating a service with CLI in Angular - Quick Revision & Summary

Choose your learning style9 modes available
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?
Ang new service data
Bng generate service data
Cng create service data
Dng add service data
What decorator does Angular CLI add to a generated service to enable dependency injection?
A@NgModule
B@Component
C@Injectable
D@Service
Where is the new service file created by default when running Angular CLI service generation?
Asrc/app
Bsrc/assets
Csrc/environments
Dsrc/styles
What is the purpose of the --module flag when generating a service?
ATo specify the module where the service should be registered
BTo create a new module along with the service
CTo skip creating the service file
DTo generate a component instead
What files are created when you generate a service using Angular CLI?
AA .ts file and a .css file
BA .ts file and a .html file
COnly a .ts file
DA .ts file and a .spec.ts test file
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.