Javascript 如何使用<;html>;Angular2中的模板?

Javascript 如何使用<;html>;Angular2中的模板?,javascript,angular,Javascript,Angular,我想用html文件替换我的代码内模板。我怎么做 Greeting.annotations = [ new angular.ComponentAnnotation({ selector: 'greeting' }), new angular.ViewAnnotation({ template: '<h1>Hello!</h1>' }) ]; 我使用Angular2和ES5。在模板中,您可能可以引用另一个HTM

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

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

我使用Angular2和ES5。

在模板中,您可能可以引用另一个HTML文件,例如:


作为组件注释的一部分,有一个属性
templateUrl
,可以指向HTML文件

  • 模板-指向原始HTML
  • templateUrl-指向包含HTML的URL
这与angular 1.x指令定义对象相同

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


注意-文档仍在进行中

由Angular提供,您可以使用
ComponentAnnotation
中的
TemplateUrl
以及
ViewAnnotation
中的
导入外部HTML文件。此外,您还可以选择在相同的
组件注释
视图注释
中使用
模板

更新: @视图已被弃用,所以提供html的唯一方法是像这样使用@component

@component({
  ..
  template: `<h1>This is inline template </h1>`
   or
  templateUrl : 'URL FOR your html page';
  ..........
})
....
@组件({
..
template:`这是内联模板`
或
templateUrl:'您的html页面的URL';
..........
})
....

templateUrl:'path/to/my/template.html'
这似乎是针对角度1而不是角度2。
@component({
  ..
  template: `<h1>This is inline template </h1>`
   or
  templateUrl : 'URL FOR your html page';
  ..........
})
....