Complete the code to inject the service into the component constructor.
constructor(private [1]: DataService) {}The service instance name in the constructor should start with a lowercase letter by convention. Here, dataService is the correct instance name.
Complete the code to add the service to the component's providers array.
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
providers: [[1]]
})The providers array requires the service class name, not an instance name.
Fix the error in the constructor injection by completing the code.
constructor([1] dataService: DataService) {}The service must be injected with the private keyword to be accessible inside the component.
Fill both blanks to correctly inject and use the service in the component.
constructor(private [1]: [2]) {} ngOnInit() { this.[1].fetchData(); }
The constructor parameter name should be dataService and the type should be DataService. Then you can call fetchData() on the instance.
Fill all three blanks to create a standalone component that injects a service using Angular 17+ patterns.
import { Component, inject } from '@angular/core'; import { [1] } from './data.service'; @Component({ selector: 'app-standalone', standalone: true, template: `<p>{{ message }}</p>` }) export class StandaloneComponent { private dataService = [2]([3]); message = this.dataService.getMessage(); }
Import the service class DataService, use the inject function to inject it, and pass DataService as the argument.