无法识别TypeScript多行代码

时间:2017-02-09 11:34:04

标签: angular typescript sublimetext3 visual-studio-code

在使用Sublime和VS Code中的Typescript编码时,请帮我解决此错误。如果所有template:代码都在一行中,则只能在浏览器中识别并正确显示。

template:'<h1>{{title}}</h1><h2>{{hero.name}} details!</h2><div><label>id: </label>{{hero.id}}</div><div><label>name: </label>{{hero.name}}</div>',

当我尝试将其分解为几行时,浏览器无法按预期显示结果。

以下是我正在做的完整代码:

import { Component } from '@angular/core';

export class Hero {
    id: number;
    name: string;
}

@Component({
    selector: 'my-app',
    template:'<h1>{{title}}</h1><h2>{{hero.name}} details!</h2><div><label>id: </label>{{hero.id}}</div><div><label>name: </label>{{hero.name}}</div>',
})

export class AppComponent {
    title = 'Tour of Heroes';
    hero = Hero {
        id: 1;
        name: 'Windstorm';
    }   
}

本教程来自angular.io

1 个答案:

答案 0 :(得分:3)

编写多行时需要使用反引号

def ctChart = chart.getCTChart()
def ctPieChart = ctChart.getPlotArea().addNewPieChart()
def ctPieSer = ctPieChart.addNewSer()

byte[] b = new byte[3];

(0 .. rows).each {
  random.nextBytes(b)
  def x = ctPieSer.addNewDPt()
  x.addNewIdx().setVal(it)
  x.addNewBubble3D().setVal(false)
  x.addNewSpPr().addNewSolidFill().addNewSrgbClr().setVal(b)
}

使用包含大量HTML的模板。

@Component({
    template: `
        //code here
    `
})

希望有所帮助