【问题标题】:Angular 2 / TypeScript multi line string in Visual Studio CodeVisual Studio Code 中的 Angular 2 / TypeScript 多行字符串
【发布时间】:2017-06-23 10:06:36
【问题描述】:

我正在 Visual Studio Code 中编写自定义组件,并希望将字符串值分配给属性。但是我需要将字符串分成多行。但是每当我这样做时,VSCode 都会给我一个问题列表。

这就是我想要达到的目标:

【问题讨论】:

    标签: angularjs string typescript visual-studio-code


    【解决方案1】:

    您可以使用+ 连接运算符换行:

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

    或者`反引号

    template: `<h1>
        </h1>`
    

    \ 反斜杠

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

    【讨论】:

    • 严格来说,Parth Ghiya 的回复是正确的。模板字符串不再允许使用单引号: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.
    【解决方案2】:

    您需要使用 backTick 来包含多行字符串文字。 这是 ES6 的一个特性

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

    【讨论】:

      猜你喜欢
      • 2016-07-29
      • 2016-05-15
      • 2016-12-29
      • 2023-02-06
      • 2018-02-03
      • 1970-01-01
      • 2018-04-06
      • 1970-01-01
      • 2017-02-13
      相关资源
      最近更新 更多