Angular - Services and Dependency Injection
Consider this Angular service and component:
What will be printed in the console when SampleComponent is instantiated?
import { Injectable } from '@angular/core';
@Injectable({providedIn: 'root'})
export class MessageService {
getMessage() { return 'Hello'; }
}
@Component({selector: 'app-sample', template: ''})
export class SampleComponent {
constructor(private msgService: MessageService) {
console.log(this.msgService.getMessage());
}
}What will be printed in the console when SampleComponent is instantiated?
