115 lines
2.9 KiB
TypeScript
Raw Normal View History

import {CONST, Type} from 'angular2/src/core/facade/lang';
2015-08-20 14:28:25 -07:00
import {ViewEncapsulation} from 'angular2/src/core/render/api';
2015-08-20 14:28:25 -07:00
export {ViewEncapsulation} from 'angular2/src/core/render/api';
/**
* Declares the available HTML templates for an application.
2015-03-30 17:19:27 -07:00
*
* Each Angular component requires a single `@Component` and at least one `@View` annotation. The
* `@View` annotation specifies the HTML template to use, and lists the directives that are active
* within the template.
2015-03-30 17:19:27 -07:00
*
2015-05-20 09:48:15 -07:00
* When a component is instantiated, the template is loaded into the component's shadow root, and
* the expressions and statements in the template are evaluated against the component.
2015-03-30 17:19:27 -07:00
*
* For details on the `@Component` annotation, see {@link ComponentMetadata}.
2015-03-30 17:19:27 -07:00
*
* ## Example
*
* ```
* @Component({
* selector: 'greet'
* })
* @View({
2015-04-10 11:15:01 -07:00
* template: 'Hello {{name}}!',
* directives: [GreetUser, Bold]
2015-03-30 17:19:27 -07:00
* })
* class Greet {
* name: string;
*
* constructor() {
* this.name = 'World';
* }
* }
* ```
*/
2015-05-20 09:48:15 -07:00
@CONST()
export class ViewMetadata {
2015-07-07 22:09:19 +02:00
/**
* Specifies a template URL for an Angular component.
2015-07-07 22:09:19 +02:00
*
* NOTE: either `templateUrl` or `template` should be used, but not both.
*/
templateUrl: string;
2015-04-15 22:35:38 +00:00
/**
* Specifies an inline template for an Angular component.
2015-04-15 22:35:38 +00:00
*
* NOTE: either `templateUrl` or `template` should be used, but not both.
2015-04-15 22:35:38 +00:00
*/
2015-07-07 22:09:19 +02:00
template: string;
2015-04-15 22:35:38 +00:00
/**
* Specifies stylesheet URLs for an Angular component.
2015-04-15 22:35:38 +00:00
*/
styleUrls: string[];
2015-07-07 22:09:19 +02:00
/**
* Specifies an inline stylesheet for an Angular component.
2015-07-07 22:09:19 +02:00
*/
styles: string[];
2015-04-15 22:35:38 +00:00
/**
* Specifies a list of directives that can be used within a template.
2015-04-15 22:35:38 +00:00
*
* Directives must be listed explicitly to provide proper component encapsulation.
*
* ## Example
*
* ```javascript
* @Component({
* selector: 'my-component'
* })
* @View({
* directives: [NgFor]
2015-04-15 22:35:38 +00:00
* template: '
* <ul>
2015-05-13 11:30:59 +02:00
* <li *ng-for="#item of items">{{item}}</li>
2015-04-15 22:35:38 +00:00
* </ul>'
* })
* class MyComponent {
* }
* ```
*/
directives: Array<Type | any[]>;
2015-04-15 22:35:38 +00:00
pipes: Array<Type | any[]>;
2015-04-20 11:34:53 -07:00
/**
* Specify how the template and the styles should be encapsulated.
* The default is {@link ViewEncapsulation#Emulated `ViewEncapsulation.Emulated`} if the view
* has styles,
* otherwise {@link ViewEncapsulation#None `ViewEncapsulation.None`}.
2015-04-20 11:34:53 -07:00
*/
encapsulation: ViewEncapsulation;
constructor({templateUrl, template, directives, pipes, encapsulation, styles, styleUrls}: {
2015-07-07 22:09:19 +02:00
templateUrl?: string,
template?: string,
directives?: Array<Type | any[]>,
pipes?: Array<Type | any[]>,
encapsulation?: ViewEncapsulation,
styles?: string[],
styleUrls?: string[],
2015-07-07 22:09:19 +02:00
} = {}) {
this.templateUrl = templateUrl;
this.template = template;
this.styleUrls = styleUrls;
this.styles = styles;
this.directives = directives;
this.pipes = pipes;
this.encapsulation = encapsulation;
2015-07-07 22:09:19 +02:00
}
}