99 lines
2.2 KiB
JavaScript
Raw Normal View History

import {ABSTRACT, CONST, Type} from 'angular2/src/facade/lang';
/**
* 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
2015-03-30 17:19:27 -07:00
* annotation specifies the HTML template to use, and lists the directives that are active within the template.
*
* 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.
*
* For details on the `@Component` annotation, see {@link Component}.
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';
* }
* }
* ```
*
* @exportedAs angular2/annotations
*/
export class View {
2015-04-15 22:35:38 +00:00
/**
* Specifies a template URL 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-19 14:47:02 -07:00
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-19 14:47:02 -07:00
template: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: [For]
* template: '
* <ul>
* <li *for="item in items">{{item}}</li>
* </ul>'
* })
* class MyComponent {
* }
* ```
*/
2015-04-19 14:47:02 -07:00
directives:List<Type>;
2015-04-15 22:35:38 +00:00
2015-04-20 11:34:53 -07:00
/**
* Specify a custom renderer for this View.
* If this is set, neither `template`, `templateURL` nor `directives` are used.
*/
renderer:any; // string;
@CONST()
2014-09-25 16:53:32 -07:00
constructor({
templateUrl,
template,
2015-04-20 11:34:53 -07:00
directives,
renderer
}: {
templateUrl: string,
template: string,
2015-04-20 11:34:53 -07:00
directives: List<Type>,
renderer: string
})
{
this.templateUrl = templateUrl;
this.template = template;
this.directives = directives;
2015-04-20 11:34:53 -07:00
this.renderer = renderer;
}
}