Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2.0. Difference @View @Component

Tags:

angular

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.

like image 257
Florian Tavares Avatar asked Oct 28 '15 20:10

Florian Tavares


People also ask

What does the @component decorator do for an Angular component?

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.

What is view component in Angular?

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.

What is component in Angular stack overflow?

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.

What is the component in Angular 8?

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.


1 Answers

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.

like image 184
alexpods Avatar answered Oct 17 '22 22:10

alexpods