0

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:

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?

Marc Le Bihan
  • 2,308
  • 2
  • 23
  • 41

2 Answers2

1

You have to use string interpolation `` and you are using single quotes ''

Max Tuzenko
  • 1,051
  • 6
  • 18
1

Use `` instead of ""

var a = "Bob"
var message = `Hello ${a}` 
Enam Kyei
  • 86
  • 1
  • 5