SERVICIOS EN ANGULAR

Para crear un service en angular ejecutar:
$ ng g s modules/intranet/services/maestra –skipTest

Luego adicionar código de tal forma que tengas algo asi:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { MaestraRequest } from '../dto/request/maestra.request';
import { Observable } from 'rxjs';
import { ApiOutResponse } from '../dto/response/api-out.response';
import { MaestraResponse } from '../dto/response/maestra.response';
import { BuscarMaestraRequest } from '../dto/request/buscar-maestra.request';
import { environment } from 'src/environments/environment';
 
@Injectable({
  providedIn: 'root'
})
export class MaestraService {
 
  constructor(private httpHttpClient) { }
 
  public listarMaestra(requestBuscarMaestraRequest): Observable<ApiOutResponse<MaestraResponse[]>> {
    return this.http.post<ApiOutResponse<MaestraResponse[]>>(`${environment.webServiceEndpoint}/maestra/lista`request);
  }
 
  public regMaestra(requestMaestraRequest): Observable<ApiOutResponse<MaestraResponse>> {
    return this.http.post<ApiOutResponse<MaestraResponse>>(`${environment.webServiceEndpoint}/maestra/registrar`request);
  }
 
  public modifMaestra(requestMaestraRequest): Observable<ApiOutResponse<MaestraResponse>> {
    return this.http.post<ApiOutResponse<MaestraResponse>>(`${environment.webServiceEndpoint}/maestra/modificar`request);
  }
}
 
Existen 2 maneras de Inyectar servicios en modulos de angular

A) Proveido en la raíz
Para este caso el clase Servicio tiene que tener la anotación como se muestra
@Injectable({
  providedIn: 'root'
})
 
Y en el modulo raíz se debe importar el modulo HttpClientModule
import { HttpClientModule } from '@angular/common/http';
 
@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AppRoutingModule,
    HttpClientModule // IMPORTACION PARA SERVICIOS PROVIDED IN ROOT
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
 
 
B) Proveido en cualquier modulo
Para este tipo la anotación debe ser como se muestra
@Injectable()
 
Y en el modulo de debe importar el modulo HttpClientModule y adicional se debe importar los servicios en el array providers
import { MaestraService } from './services/maestra.service';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
  entryComponents: [],
  declarations: [
    HomeComponent,
  ],
  imports: [
    CommonModule,
    IntranetRoutingModule,
    LayoutModule,
    HttpClientModule,//IMPORTACION DEL MODULO HTTP PARA LOS SERVICIOS
  ],
  providers:[
    MaestraService//IMPORTACION DE LOS SERVICIOS
  ]
})
export class IntranetModule { }