
- Angular 2 Tutorial
- Angular 2 - Home
- Angular 2 - Overview
- Angular 2 - Environment
- Angular 2 - Hello World
- Angular 2 - Modules
- Angular 2 - Architecture
- Angular 2 - Components
- Angular 2 - Templates
- Angular 2 - Directives
- Angular 2 - Metadata
- Angular 2 - Data Binding
- CRUD Operations Using HTTP
- Angular 2 - Error Handling
- Angular 2 - Routing
- Angular 2 - Navigation
- Angular 2 - Forms
- Angular 2 - CLI
- Angular 2 - Dependency Injection
- Angular 2 - Advanced Configuration
- Angular 2 - Third Party Controls
- Angular 2 - Data Display
- Angular 2 - Handling Events
- Angular 2 - Transforming Data
- Angular 2 - Custom Pipes
- Angular 2 - User Input
- Angular 2 - Lifecycle Hooks
- Angular 2 - Nested Containers
- Angular 2 - Services
- Angular 2 Useful Resources
- Angular 2 - Questions and Answers
- Angular 2 - Quick Guide
- Angular 2 - Useful Resources
- Angular 2 - Discussion
Angular 2 - Metadata
Metadata is used to decorate a class so that it can configure the expected behavior of the class. Following are the different parts for metadata.
Annotations − These are decorators at the class level. This is an array and an example having both the @Component and @Routes decorator.
Following is a sample code, which is present in the app.component.ts file.
@Component ({ selector: 'my-app', templateUrl: 'app/app.component.html' })
The component decorator is used to declare the class in the app.component.ts file as a component.
Design:paramtypes − These are only used for the constructors and applied only to Typescript.
propMetadata − This is the metadata which is applied to the properties of the class.
Following is an example code.
export class AppComponent { @Environment(‘test’) appTitle: string = 'Welcome'; }
Here, the @Environment is the metadata applied to the property appTitle and the value given is ‘test’.
Parameters − This is set by the decorators at the constructor level.
Following is an example code.
export class AppComponent { constructor(@Environment(‘test’ private appTitle:string) { } }
In the above example, metadata is applied to the parameters of the constructor.