3

In the Angular.io docs it says that "Each Angular component requires a single @Component and at least one @View annotation." LINK But even the example that it has, does not use an @View annotation.

My question is, what is the difference between using @View or specifying the parameters (templateUrl, StyleUrls, Etc.) in the @Component annotation?

Thanks guys!

Zorthgo
  • 2,857
  • 6
  • 25
  • 37

2 Answers2

4

As you can see here - @View is now optional (the docs are outdated).

Both options are the same - using @View as a separate annotation (for later use of different view per component) or using 'template' etc from within @Component annotation.

Hope that answers your question.

Yaniv Efraim
  • 6,633
  • 7
  • 53
  • 96
  • Thanks @YanivEfraim! So the docs are out of date. Good to know. Yeah, because I prefer specifying all of my templates and such inside my Component annotation. But then I read on the docs that I had to use View. So I got a little confused. Thanks for the help! ;) – Zorthgo Nov 10 '15 at 03:05
  • Here's were/when the change was made. Ref: https://github.com/angular/angular/pull/4566 – Evan Plaice Feb 21 '16 at 07:50
0

As i read from the officials of angular2 there is nothing major difference between these two. @View is optional. Still there is something which differentiate these two in the future:

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

This feature is not implemented yet.but may be used in the future as said by @alexpods here. i hope this will clear the difference upto some extent.

Community
  • 1
  • 1
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215