Complete the code to inject the service into the constructor.
constructor(private readonly [1]: CatsService) {}The injected service should be a private readonly property with a camelCase name, usually the service name starting with a lowercase letter.
Complete the code to declare the service type in the constructor.
constructor(private readonly catsService: [1]) {}The type of the injected service should be the service class name, which is CatsService.
Fix the error in the constructor injection syntax.
constructor([1] catsService: CatsService) {}To properly inject a service in NestJS, the constructor parameter must be marked private readonly to create and assign the property automatically.
Fill both blanks to complete the service injection and usage.
export class CatsController { constructor([1] catsService: CatsService) {} findAll() { return this.catsService.[2](); } }
The constructor parameter must be private readonly to inject the service. The method called on the service is assumed to be getCats() to fetch all cats.
Fill all three blanks to define and inject a service, then use it in a method.
import { Injectable } from '@nestjs/common'; @Injectable() export class DogsService { getDogs() { return ['Bulldog', 'Beagle']; } } export class DogsController { constructor([1] dogsService: [2]) {} listDogs() { return this.dogsService.[3](); } }
The service is injected with private readonly and typed as DogsService. The method called to get dogs is getDogs().