使用@View 注释与在@Component 注释中指定参数

Using @View annotation vs specifying parameters in the @Component annotation

在 Angular.io 文档中它说 "Each Angular component requires a single @Component and at least one @View annotation." LINK 但即使是它的示例也没有使用 @View 注释。

我的问题是,在@Component注解中使用@View和指定参数(templateUrl、StyleUrls等)有什么区别?

谢谢大家!

如您所见here - @View 现在是可选的(文档已过时)。

这两个选项是相同的——使用@View 作为单独的注解(以便以后使用每个组件的不同视图)或在@Component 注解中使用'template' 等。

希望这能回答您的问题。

正如我从 angular2 的官员那里读到的,这两者之间没有什么大的区别。 @View 是可选的。 将来仍然有一些东西可以区分这两者:

@Component(/* ... */)
@View({
  media: 'Desktop',
  template: 'Template for desktop'
})
@View({
  media: 'Mobile',
  template: 'Template for Mobile'
})
extends class Component_Name() {} 

此功能未实现 yet.but 将来可能会使用 @alexpods 所说的。我希望这会在一定程度上消除差异。