|
1 | | -import {bootstrap, Component, Decorator, TemplateConfig, NgElement} from 'core/core'; |
2 | | - |
3 | | -// Angular 2.0 supports 3 basic types of directives: |
4 | | -// - Component - the basic building blocks of Angular 2.0 apps. Backed by |
5 | | -// ShadowDom.(http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/) |
6 | | -// - Decorator - add behavior to existing elements. |
7 | | -// - Template - allow for stamping out of a html template (not in this demo). |
8 | | - |
9 | | -// @Component is AtScript syntax to annotate the HelloCmp class as an Angular |
10 | | -// 2.0 component. |
11 | | -@Component({ |
12 | | - // The Selector prop tells Angular on which elements to instantiate this |
13 | | - // class. The syntax supported is a basic subset of CSS selectors, for example |
14 | | - // 'element', '[attr]', [attr=foo]', etc. |
15 | | - selector: 'hello-app', |
16 | | - // These are services that would be created if a class in the component's |
17 | | - // template tries to inject them. |
18 | | - componentServices: [GreetingService], |
19 | | - template: new TemplateConfig({ |
20 | | - // The template for the component. |
21 | | - // Expressions in the template (like {{greeting}}) are evaluated in the |
22 | | - // context of the HelloCmp class below. |
23 | | - inline: `{{greeting}} <span red>world</span>!`, |
24 | | - // All directives used in the template need to be specified. This allows for |
25 | | - // modularity (RedDec can only be used in this template) |
26 | | - // and better tooling (the template can be invalidated if the attribute is |
27 | | - // misspelled). |
28 | | - directives: [RedDec] |
29 | | - }) |
30 | | -}) |
31 | | -class HelloCmp { |
32 | | - greeting: string; |
33 | | - constructor(service: GreetingService) { |
34 | | - this.greeting = service.greeting; |
35 | | - } |
36 | | -} |
37 | | - |
38 | | -// Decorators are light-weight. They don't allow for templates, or new |
39 | | -// expression contexts (use @Component or @Template for those needs). |
40 | | -@Decorator({ |
41 | | - selector: '[red]' |
42 | | -}) |
43 | | -class RedDec { |
44 | | - // NgElement is always injectable and it wraps the element on which the |
45 | | - // directive was found by the compiler. |
46 | | - constructor(el: NgElement) { |
47 | | - el.domElement.style.color = 'red'; |
48 | | - } |
49 | | -} |
50 | | - |
51 | | -// A service used by the HelloCmp component. |
52 | | -class GreetingService { |
53 | | - greeting:string; |
54 | | - constructor() { |
55 | | - this.greeting = 'hello'; |
56 | | - } |
57 | | -} |
| 1 | +import * as app from './index_common'; |
| 2 | +import {reflector} from 'reflection/reflection'; |
| 3 | +import {ReflectionCapabilities} from 'reflection/reflection_capabilities'; |
58 | 4 |
|
59 | 5 | export function main() { |
60 | | - // Bootstrapping only requires specifying a root component. |
61 | | - // The boundary between the Angular application and the rest of the page is |
62 | | - // the shadowDom of this root component. |
63 | | - // The selector of the component passed in is used to find where to insert the |
64 | | - // application. |
65 | | - // You can use the light dom of the <hello-app> tag as temporary content (for |
66 | | - // example 'Loading...') before the application is ready. |
67 | | - bootstrap(HelloCmp); |
| 6 | + // Initializing the reflector is only required for the Dart version of the application. |
| 7 | + // When using Dart, the reflection information is not embedded by default in the source code |
| 8 | + // to keep the size of the generated file small. Importing ReflectionCapabilities and initializing |
| 9 | + // the reflector is required to use the reflection information from Dart mirrors. |
| 10 | + // Dart mirrors are not intended to be use in production code where the transformers generate a |
| 11 | + // more optimal static configuration, see index_static.js for an example. |
| 12 | + reflector.reflectionCapabilities = new ReflectionCapabilities(); |
| 13 | + app.main(); |
68 | 14 | } |
0 commit comments