Using @View annotation and specifying parameters in @Component annotation

The Angular.io docs say, "Each Angular component requires one @Component and at least one @View annotation." LINK But even the example that he has does not use the @View annotation.

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

Thanks guys!

+3
source share
2 answers

As you can see here - @View is now optional (documents are out of date).

Both parameters are the same: using @View as a separate annotation (for subsequent use of different views for each component) or using a "template", etc. from the annotation @Component.

Hope that answers your question.

+4
source

As I read from angular2 officials, there is nothing significant difference between the two. @View is optional. However, there is something that will distinguish 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 has not yet been implemented. but may be used in the future, as @alexpods says here . I hope this changes the situation a bit.

0
source

Source: https://habr.com/ru/post/1237143/


All Articles