7

I am writing a custom component in Visual Studio Code and would like to assign a string value to a property. However I need to break the string into multiple lines. But whenever I do that VSCode gives me a list of problems.

This is what I am trying to achieve:

I can't break the string into multiple lines according to Visual Studio Code

2 Answers 2

6

You need to use backTick to include multi line String literals. This is a feature of ES6

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals

Sign up to request clarification or add additional context in comments.

Comments

5

You can break lines using + concatening operator:

template: "<h1>" +
    "</h1>"

Or ` backtick

template: `<h1>
    </h1>`

Or \ backslash

template: "<h1>\
    </h1>"

1 Comment

Strictly speaking, Parth Ghiya's reply is the correct one. Single quotes are no longer permissible for template strings: Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them. They were called "template strings" in prior editions of the ES2015 specification.

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.