加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

typescript – angular 2和template:未终止的字符串literal.at

发布时间:2020-12-17 07:19:16 所属栏目:安全 来源:网络整理
导读:在下面的代码中,由于某些原因,当我在模板后面输入一个新行时,它给了我一个错误.我的所有代码都必须在一行’ h1 … h2等等.’ – 我在模板后输入的那一刻:’输入它会给我一个错误. Unterminated string literal.at line 6 col 24 TS Error Property assignme
在下面的代码中,由于某些原因,当我在模板后面输入一个新行时,它给了我一个错误.我的所有代码都必须在一行’< h1> …< h2>等等.’ – 我在模板后输入的那一刻:’输入它会给我一个错误.

Unterminated string literal.at line 6 col 24 TS Error Property
assignment expected.at line 7 col 10 TS Error ‘,’ expected.at line 7
col 25 TS Error Type expected.at line 7 col 27 TS Error Unterminated
regular expression literal.at line 7 col 28 TS Error ‘,’ expected.at
line 8 col 1

import {Component} from 'angular2/core';

@Component({
    selector: 'ponyracer-app',template:
    '<h1>PonyRacer</h1>
     <h2>{{numberOfUsers}}</h2>'
})
export class PonyRacerApp {

    numberOfUsers: number = 146;
}
使用`(backsticks),而不是'(单引号或双引号)来声明模板字符串:
import {Component} from 'angular2/core';

@Component({
    selector: 'ponyracer-app',template:
    `<h1>PonyRacer</h1>
     <h2>{{numberOfUsers}}</h2>`
})
export class PonyRacerApp {

    numberOfUsers: number = 146;
}

当您使用它们时,您声明模板字符串,而不是常规字符串.它们是ES6的一部分(又名ECMAScript 2015):

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 / ES6 specification.

有关它的更多信息,请参见MDN或TypeScript Deep Dive.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读