Angular environment variable in index.html file

Discussão em 'Angular' iniciado por Merkury32, Abril 21, 2025.

  1. Merkury32

    Merkury32 Guest

    I would like to put environment variable from main.ts in index.html <script src="..."> tag. Index.html look like this:

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>RoadFaultReporter</title>
    <base href="./" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" type="image/x-icon" href="favicon.ico" />
    <link rel="manifest" href="manifest.webmanifest" />
    <meta name="theme-color" content="#1976d2" />
    <link rel="preconnect" href="https://fonts.gstatic.com" />
    <link
    href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap"
    rel="stylesheet"
    />
    </head>
    <body>
    <app-root></app-root>
    <noscript>Please enable JavaScript to continue using this application.</noscript>
    <script src="https://maps.googleapis.com/maps/api/js?key=MY_KEY"></script>
    </body>
    </html>



    In the place of MY_KEY in <script src=""> I would like to place a key from variable - environment.googleMapsApi. Is there any way to do this?

    Continue reading...

Compartilhe esta Página