Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

message = 'Hello ${name}' doesn't replace the name parameter in the message string immediately

I cannot make working the basic typescript feature that I see written everywhere over the Internet, that says that :

var a = "Bob"  
var message = 'Hello ${a}'  

would see a console.log(message) print "Hello Bob".

When I attempt this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import { Component } from '@angular/core';
import { environment } from '../environments/environment';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'etude';

  constructor() {
    console.log('Démarrage environnement ' + environment.nom_environnement + ' spark: ' + environment.spark_url + ' backend: ' + environment.backend_url);

    const a = 'Démarrage environnement ${environment.nom_environnement} spark: ${environment.spark_url} backend: ${environment.backend_url}';
    console.log(a);
  }
}

My console logs are showing that:

Démarrage environnement dev spark: http://localhost:9090 backend: http://localhost:9091 main.js:1:598971
Démarrage environnement ${environment.nom_environnement} spark: ${environment.spark_url} backend: ${environment.backend_url}

Whatever I try let a or var a instead of const a.

Reading over the Internet, the transformation should had happened immediately?

>Solution :

You have to use string interpolation “ and you are using single quotes ”

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading