Hi. I'm new to Angular. I'm testing Angular 2.0.
I read the tuto here and the guide here. In the tuto, the template is specified in the @Component
annotation whereas in the guide it is in the @View
annotation. So I was wondering what are the differences between the two approaches ? I looked up in the api preview but the explanations were not clear.
Description. Component decorator allows you to mark a class as an Angular component and provide additional metadata that determines how the component should be processed, instantiated and used at runtime. Components are the most basic building block of an UI in an Angular application.
A component controls a patch of screen called a view. It consists of a TypeScript class, an HTML template, and a CSS style sheet. The TypeScript class defines the interaction of the HTML template and the rendered DOM structure, while the style sheet describes its appearance.
The Component is a fundamental block of Angular and multiple components will make up your application. A module can be a library for another module. For instance, the angular2/core library which is a primary Angular library module will be imported by another component.
The component is the basic building block of Angular. It has a selector, template, style, and other properties, and it specifies the metadata required to process the component.
Update
@View()
was removed (I think in beta.13, the CHANGELOG.md doesn't mention it though).
Original
There are no differences between them. It's just sugar that you can specify all view configuration into Component
so there's no need to import View
decorator.
But at the same time there's a need to remain View
decorator exist, because it allows us to use different views for the same component depending on language or media type. For example:
@Component(/* ... */)
@View({
media: 'desktop',
template: 'Template for desktop'
})
@View({
media: 'mobile',
template: 'Template for mobile'
})
extends class Component() {}
This feature is not implemented yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With