【问题标题】:Using @View annotation vs specifying parameters in the @Component annotation使用@View 注解与在@Component 注解中指定参数
【发布时间】:2015-11-09 20:30:00
【问题描述】:

在 Angular.io 文档中,它说“每个 Angular 组件都需要一个 @Component 和至少一个 @View 注释。” LINK 但即使是它的示例,也没有使用 @View 注释。

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

谢谢大家!

【问题讨论】:

标签: angular


【解决方案1】:

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

这两个选项是相同的 - 使用 @View 作为单独的注释(以便以后使用每个组件的不同视图)或使用 @Component 注释中的“模板”等。

希望能回答你的问题。

【讨论】:

  • 感谢@YanivEfraim!所以文档已经过时了。很高兴知道。是的,因为我更喜欢在 Component 注释中指定所有模板等。但后来我阅读了我必须使用 View 的文档。所以我有点困惑。谢谢您的帮助! ;)
  • 这里是/何时进行更改。参考:github.com/angular/angular/pull/4566
【解决方案2】:

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

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

此功能尚未实现。但如@alexpods here 所说,将来可能会使用。我希望这会在一定程度上消除差异。

【讨论】:

    猜你喜欢
    • 2016-12-12
    • 2021-11-07
    • 2016-10-31
    • 1970-01-01
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    相关资源
    最近更新 更多