Loading

Quipoin Menu

Learn • Practice • Grow

angular / Creating a Service
mcq
Direction: Choose the correct option

Q1.

Which Angular CLI command generates a service?
A. ng make service data
B. ng create service data
C. ng generate service data
D. ng new service data
Direction: Choose the correct option

Q2.

What is the default file extension for a generated service?
A. .service
B. .serv.ts
C. .service.ts
D. .ts
Direction: Choose the correct option

Q3.

What does the `providedIn` property in @Injectable do?
A. Provides the service name
B. Indicates the service is provided
C. Specifies where the service is provided (root, module, etc.)
D. Configures the service
Direction: Choose the correct option

Q4.

If `providedIn` is not specified, how can you provide the service?
A. Both A and B
B. It cannot be provided
C. In the module's providers array
D. In the component's providers array
Direction: Choose the correct option

Q5.

What is the advantage of `providedIn: 'root'`?
A. Automatic injection
B. Tree-shaking: service is only included if used
C. Faster instantiation
D. No need to import
Direction: Choose the correct option

Q6.

What does the `--flat` flag do when generating a service?
A. Creates a flat structure
B. Creates the service without a folder
C. Removes indentation
D. Makes the service flat
Direction: Choose the correct option

Q7.

How do you generate a service in a specific module?
A. ng g s feature/data
B. ng g s feature/data --module
C. ng g s feature/data.module
D. ng g s feature/data --module=feature
Direction: Choose the correct option

Q8.

What is the default behavior of `ng generate service` regarding `providedIn`?
A. Creates `providedIn: 'any'`
B. Creates `providedIn: 'root'` by default
C. No `providedIn`
D. Creates `providedIn: null`
Direction: Choose the correct option

Q9.

Can you have multiple services with the same name in different folders?
A. Only in different projects
B. No, names must be unique
C. Only with aliases
D. Yes, as long as they are in different Angular modules or have different paths
Direction: Choose the correct option

Q10.

What is the purpose of the `--skip-tests` flag when generating a service?
A. Skips tests in the service
B. Skips test configuration
C. Skips test module
D. Prevents generating a test (.spec) file