How to property escape $ { } in environment.ts?

Discussão em 'Angular' iniciado por Hasan Can Saral, Agosto 30, 2025.

  1. In my Angular app, I read a string from environment.ts:

    {
    "sampleString": "This is a ${placeholder}\nThis is another one ${another}"
    }


    And in component, I replace them as:

    let key = 'placeholder';
    sampleString = sampleString.replace(`\$\{${key}\}`, 'myValue');
    key = 'another';
    sampleString = sampleString.replace(`\$\{${key}\}`, 'secondValue');


    and this works fine in my local environemnt:

    This is a myValue
    This is another one secondValue


    But when I run ng build and deploy I get:

    This is a
    This is another one


    I've tried escaping in environement.ts like: \${placeholder} and ${another}, which yielded to:

    This is a\nThis is another one


    and like: \$\{placeholder\} which gave:

    This is a
    This is another one


    How do I put it in environment.ts so that I get it as I do in my local?

    Continue reading...

Compartilhe esta Página