0

I started to work with Angular for a work-related project and am following this tutorial https://www.youtube.com/watch?v=2OHbjep_WjQ&t=1874s (minute 50:30)

Which led me to following code-snippet

  i=0;
  doSomeHeavyTask()
  {
    console.log('Called ${this.i++} times');
  }

The browser should print following message into the console:

Called 0 times

Called 1 times

...

But VSCode doesnt recognize

${this.i++}

as an JS-expression, therefore it prints just the plain text. The syntax also doesn't get highlighted and is handled like a normal string.

I can't find the reason behind this behaviour and couldn't find any other person with that problem. I would be happy if somebody could come up with a suggestion or a solution :)

1
  • For that to work you need to use template literals, i.e. console.log(`Called ${this.i++} times`);. Wrap the template literals with backticks (`) and not quotes. Commented Apr 13, 2019 at 16:44

1 Answer 1

4

You used the wrong character for the template literal syntax. It should be the backtick (on keyboard, usually left of the 1 key), not the single quotation mark.

console.log(`Called ${this.i++} times`);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.