Mi archivo de entorno
export environment = { local: true, title: 'Local Environment Heading', API URL : 'http://localhost:8090/myapp/', staging: false, production: false, };Archivo de servicio común
// here I want to read this API URLEn este caso, tiene un error en su archivo de entorno. Verifique que la URL de la API del nombre no pueda contener espacios en el nombre. Y olvidaste la const en la exportación. (Exportar entorno constante)
export const environment = { local: true, title: 'Local Environment Heading', baseUrl : 'http://localhost:8090/myapp/', staging: false, production: false, };Después de arreglar eso, es muy fácil de usar. Solo tienes que importar el archivo de entorno.
Por ejemplo en un servicio.
import { Injectable } from '@angular/core'; import { environment } from 'src/environments/environment'; @Injectable({ providedIn: 'root' }) export class AuthServiceService { constructor() { const a = environment.baseUrl } }