2015-11-23 26 views
2

我想用html文件替换我的代码内模板。我该怎么做?如何在Angular2中使用<html>模板?

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

我想是这样的

template: 'path/to/my/template.html' 

我用Angular2和ES5。

+4

'templateUrl:“路径/要/我的/ template.html'' –

回答

6

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

  • 模板 - 点,原始的HTML
  • templateUrl - 在URL包含HTML

这是一样的角度1.x的指令定义对象

你可以找到点多有关组件属性的信息here

备注 - 个文档仍在进行中

-4

也许在你的模板,你可以参考另一个HTML文件,如:

<ng-include src="'templates/[new template file].html'"></ng-include> 
+1

这似乎是为Angular 1而不是Angular 2。 – Harry

1

工作如角官员只要你能在ComponentAnnotationViewAnnotation使用TemplateUrl导入外部HTML文件以及太。此外,您可以选择在同一ComponentAnnotationViewAnnotation中使用Template

更新:

@view已被弃用,因此只能提供HTML方式是使用@Component这样

@component({ 
    .. 
    template: `<h1>This is inline template </h1>` 
    or 
    templateUrl : 'URL FOR your html page'; 
    .......... 
}) 
....