-1

Following is code for an Angular project service:

@Injectable()
export class FetchDataService {
  fetch(link){
    console.log('this is a ${link}');
  }
}

I'm calling this method in the component passing a string as an arguement.

Console Output: the link is ${link}

  • If you use the 3 first words of your question on a google search, you will notice that your error is a typo: you arent using backticks. https://basarat.gitbooks.io/typescript/docs/template-strings.html – Jota.Toledo Jun 03 '18 at 13:54

2 Answers2

6

Try with backticks like so

@Injectable()
export class FetchDataService {
  fetch(link){
    console.log(`this is a ${link}`);
  }
}

It's called template literal and you can find more info here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

Vuk Stanković
  • 7,864
  • 10
  • 41
  • 65
0

You can to use following:

console.log('this is a' + link);
POV
  • 11,293
  • 34
  • 107
  • 201