Web / Angular Interview questions
Explain Angular services.
Services are a great way to share information among components/classes that don't know each other. Services can be injected into any component and it usually holds data/code providing data for one or more components.
To create a service using angular CLI, use the below command.
ng g service searchAPI
The above command generates 2 files, search-api.service.ts, and search-api.service.spec.ts, hold the code related to service and unit test specification for the service respectively.
search-api.service.ts file generated content follows:
import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class SearchAPIService { constructor() { } }
More Related questions...