如何在Angular2中使用<html>模板?

Aar*_*ron 2 javascript angular

我想用html文件替换我的代码内模板.我该怎么做?

Greeting.annotations = [
    new angular.ComponentAnnotation({
        selector: 'greeting'
    }),
    new angular.ViewAnnotation({
        template: '<h1>Hello!</h1>'
    })
];
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西

template: 'path/to/my/template.html'
Run Code Online (Sandbox Code Playgroud)

我使用Angular2和ES5.

Bro*_*cco 6

由于部分ComponentAnnotation有一个属性templateUrl,你可以在一个HTML文件指向.

  • 模板 - 指向原始HTML
  • templateUrl - 指向包含HTML的URL

这与angular 1.x指令定义对象相同

您可以在此处找到有关组件属性的更多信息

注意 - 文档仍在进行中