Complete the code to inject a service into a component constructor.
constructor(private [1]: DataService) {}The service instance is injected by naming a private variable in the constructor. The variable name is usually camelCase.
Complete the code to provide a service at the root level.
@Injectable({ providedIn: '[1]' })
export class DataService {}Providing a service in 'root' makes it a singleton available throughout the app.
Fix the error in the constructor injection syntax.
constructor([1] dataService: DataService) {}The constructor parameter must be marked private (or public/protected) to create and assign the property automatically.
Fill both blanks to inject a service and use it in ngOnInit.
constructor(private [1]: LoggerService) {} ngOnInit() { this.[2].log('Component started'); }
The injected service variable is named 'logger' and used with 'this.logger' to call its methods.
Fill all three blanks to create a service, provide it, and inject it in a component.
import { Injectable } from '@angular/core'; @Injectable({ providedIn: '[1]' }) export class AuthService {} @Component({ selector: 'app-login', templateUrl: './login.component.html' }) export class LoginComponent { constructor(private [2]: AuthService) {} login() { this.[3].authenticate(); } }
The service is provided in 'root', injected as 'authService', and used via 'this.authService'.