diff --git a/modules/angular2/core.js b/modules/angular2/core.js index 6e164a4d13..518edd0518 100644 --- a/modules/angular2/core.js +++ b/modules/angular2/core.js @@ -5,7 +5,6 @@ * Define angular core API here. */ export * from './src/core/annotations/visibility'; -export * from './src/core/compiler/interfaces'; export * from './src/core/annotations/view'; export * from './src/core/application'; export * from './src/core/application_tokens'; diff --git a/modules/angular2/globals.d.ts b/modules/angular2/globals.d.ts index 56e1ed6751..f544935e04 100644 --- a/modules/angular2/globals.d.ts +++ b/modules/angular2/globals.d.ts @@ -27,4 +27,5 @@ interface Window { Reflect: any; zone: Zone; Hammer: HammerStatic; + getAngularTestability: Function; } diff --git a/modules/angular2/src/change_detection/change_detection.ts b/modules/angular2/src/change_detection/change_detection.ts index fa5662617d..3cc06083a9 100644 --- a/modules/angular2/src/change_detection/change_detection.ts +++ b/modules/angular2/src/change_detection/change_detection.ts @@ -77,19 +77,19 @@ export var preGeneratedProtoDetectors = {}; */ export class PreGeneratedChangeDetection extends ChangeDetection { _dynamicChangeDetection: ChangeDetection; - _protoChangeDetectors: any; + _protoChangeDetectorFactories: StringMap; constructor(private registry: PipeRegistry, protoChangeDetectors?) { super(); this._dynamicChangeDetection = new DynamicChangeDetection(registry); - this._protoChangeDetectors = + this._protoChangeDetectorFactories = isPresent(protoChangeDetectors) ? protoChangeDetectors : preGeneratedProtoDetectors; } createProtoChangeDetector(definition: ChangeDetectorDefinition): ProtoChangeDetector { var id = definition.id; - if (StringMapWrapper.contains(this._protoChangeDetectors, id)) { - return StringMapWrapper.get(this._protoChangeDetectors, id)(this.registry); + if (StringMapWrapper.contains(this._protoChangeDetectorFactories, id)) { + return StringMapWrapper.get(this._protoChangeDetectorFactories, id)(this.registry); } return this._dynamicChangeDetection.createProtoChangeDetector(definition); } diff --git a/modules/angular2/src/core/annotations/annotations.es6 b/modules/angular2/src/core/annotations/annotations.ts similarity index 86% rename from modules/angular2/src/core/annotations/annotations.es6 rename to modules/angular2/src/core/annotations/annotations.ts index 1cef71cfb3..e9dde7d412 100644 --- a/modules/angular2/src/core/annotations/annotations.es6 +++ b/modules/angular2/src/core/annotations/annotations.ts @@ -6,5 +6,7 @@ export { Component as ComponentAnnotation, Directive as DirectiveAnnotation, - onDestroy, onChange, onAllChangesDone + onDestroy, + onChange, + onAllChangesDone } from '../annotations_impl/annotations'; diff --git a/modules/angular2/src/core/annotations/decorators.es6 b/modules/angular2/src/core/annotations/decorators.ts similarity index 90% rename from modules/angular2/src/core/annotations/decorators.es6 rename to modules/angular2/src/core/annotations/decorators.ts index 48fed20015..f5e80b89e5 100644 --- a/modules/angular2/src/core/annotations/decorators.es6 +++ b/modules/angular2/src/core/annotations/decorators.ts @@ -1,7 +1,4 @@ -import { - ComponentAnnotation, - DirectiveAnnotation -} from './annotations'; +import {ComponentAnnotation, DirectiveAnnotation} from './annotations'; import {ViewAnnotation} from './view'; import {AncestorAnnotation, ParentAnnotation} from './visibility'; import {AttributeAnnotation, QueryAnnotation} from './di'; diff --git a/modules/angular2/src/core/annotations/di.es6 b/modules/angular2/src/core/annotations/di.ts similarity index 100% rename from modules/angular2/src/core/annotations/di.es6 rename to modules/angular2/src/core/annotations/di.ts diff --git a/modules/angular2/src/core/annotations/view.es6 b/modules/angular2/src/core/annotations/view.es6 deleted file mode 100644 index 504e1866b4..0000000000 --- a/modules/angular2/src/core/annotations/view.es6 +++ /dev/null @@ -1,3 +0,0 @@ -export { - View as ViewAnnotation, - } from '../annotations_impl/view'; diff --git a/modules/angular2/src/core/annotations/view.ts b/modules/angular2/src/core/annotations/view.ts new file mode 100644 index 0000000000..8aee85b989 --- /dev/null +++ b/modules/angular2/src/core/annotations/view.ts @@ -0,0 +1,3 @@ +export { + View as ViewAnnotation, +} from '../annotations_impl/view'; diff --git a/modules/angular2/src/core/annotations/visibility.es6 b/modules/angular2/src/core/annotations/visibility.ts similarity index 62% rename from modules/angular2/src/core/annotations/visibility.es6 rename to modules/angular2/src/core/annotations/visibility.ts index 6b768671d0..53acffc1fb 100644 --- a/modules/angular2/src/core/annotations/visibility.es6 +++ b/modules/angular2/src/core/annotations/visibility.ts @@ -1,4 +1,4 @@ export { Ancestor as AncestorAnnotation, Parent as ParentAnnotation, - } from '../annotations_impl/visibility'; +} from '../annotations_impl/visibility'; diff --git a/modules/angular2/src/core/annotations_impl/annotations.js b/modules/angular2/src/core/annotations_impl/annotations.ts similarity index 81% rename from modules/angular2/src/core/annotations_impl/annotations.js rename to modules/angular2/src/core/annotations_impl/annotations.ts index 3890bf64dc..32b9b4768a 100644 --- a/modules/angular2/src/core/annotations_impl/annotations.js +++ b/modules/angular2/src/core/annotations_impl/annotations.ts @@ -1,4 +1,4 @@ -import {CONST, normalizeBlank, isPresent} from 'angular2/src/facade/lang'; +import {CONST, normalizeBlank, isPresent, CONST_EXPR} from 'angular2/src/facade/lang'; import {ListWrapper, List} from 'angular2/src/facade/collection'; import {Injectable} from 'angular2/src/di/annotations_impl'; import {DEFAULT} from 'angular2/change_detection'; @@ -10,29 +10,38 @@ import {DEFAULT} from 'angular2/change_detection'; * * {@link Directive}s with an embedded view are called {@link Component}s. * - * A directive consists of a single directive annotation and a controller class. When the directive's `selector` matches + * A directive consists of a single directive annotation and a controller class. When the + * directive's `selector` matches * elements in the DOM, the following steps occur: * - * 1. For each directive, the `ElementInjector` attempts to resolve the directive's constructor arguments. - * 2. Angular instantiates directives for each matched element using `ElementInjector` in a depth-first order, + * 1. For each directive, the `ElementInjector` attempts to resolve the directive's constructor + * arguments. + * 2. Angular instantiates directives for each matched element using `ElementInjector` in a + * depth-first order, * as declared in the HTML. * * ## Understanding How Injection Works * * There are three stages of injection resolution. * - *Pre-existing Injectors*: - * - The terminal {@link Injector} cannot resolve dependencies. It either throws an error or, if the dependency was + * - The terminal {@link Injector} cannot resolve dependencies. It either throws an error or, if + * the dependency was * specified as `@Optional`, returns `null`. - * - The platform injector resolves browser singleton resources, such as: cookies, title, location, and others. - * - *Component Injectors*: Each component instance has its own {@link Injector}, and they follow the same parent-child hierarchy + * - The platform injector resolves browser singleton resources, such as: cookies, title, + * location, and others. + * - *Component Injectors*: Each component instance has its own {@link Injector}, and they follow + * the same parent-child hierarchy * as the component instances in the DOM. - * - *Element Injectors*: Each component instance has a Shadow DOM. Within the Shadow DOM each element has an `ElementInjector` + * - *Element Injectors*: Each component instance has a Shadow DOM. Within the Shadow DOM each + * element has an `ElementInjector` * which follow the same parent-child hierarchy as the DOM elements themselves. * - * When a template is instantiated, it also must instantiate the corresponding directives in a depth-first order. The + * When a template is instantiated, it also must instantiate the corresponding directives in a + * depth-first order. The * current `ElementInjector` resolves the constructor dependencies for each directive. * - * Angular then resolves dependencies as follows, according to the order in which they appear in the {@link View}: + * Angular then resolves dependencies as follows, according to the order in which they appear in the + * {@link View}: * * 1. Dependencies on the current element * 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM boundary @@ -40,26 +49,34 @@ import {DEFAULT} from 'angular2/change_detection'; * 4. Dependencies on pre-existing injectors * * - * The `ElementInjector` can inject other directives, element-specific special objects, or it can delegate to the parent + * The `ElementInjector` can inject other directives, element-specific special objects, or it can + * delegate to the parent * injector. * * To inject other directives, declare the constructor parameter as: * - `directive:DirectiveType`: a directive on the current element only - * - `@Ancestor() directive:DirectiveType`: any directive that matches the type between the current element and the - * Shadow DOM root. Current element is not included in the resolution, therefore even if it could resolve it, it will + * - `@Ancestor() directive:DirectiveType`: any directive that matches the type between the current + * element and the + * Shadow DOM root. Current element is not included in the resolution, therefore even if it could + * resolve it, it will * be ignored. - * - `@Parent() directive:DirectiveType`: any directive that matches the type on a direct parent element only. - * - `@Query(DirectiveType) query:QueryList`: A live collection of direct child directives. - * - `@QueryDescendants(DirectiveType) query:QueryList`: A live collection of any child directives. + * - `@Parent() directive:DirectiveType`: any directive that matches the type on a direct parent + * element only. + * - `@Query(DirectiveType) query:QueryList`: A live collection of direct child + * directives. + * - `@QueryDescendants(DirectiveType) query:QueryList`: A live collection of any + * child directives. * * To inject element-specific special objects, declare the constructor parameter as: * - `element: ElementRef` to obtain a reference to logical element in the view. - * - `viewContainer: ViewContainerRef` to control child template instantiation, for {@link Directive} directives only + * - `viewContainer: ViewContainerRef` to control child template instantiation, for {@link + * Directive} directives only * - `bindingPropagation: BindingPropagation` to control change detection in a more granular way. * * ## Example * - * The following example demonstrates how dependency injection resolves constructor arguments in practice. + * The following example demonstrates how dependency injection resolves constructor arguments in + * practice. * * * Assume this HTML template: @@ -100,7 +117,8 @@ import {DEFAULT} from 'angular2/change_detection'; * * ### No injection * - * Here the constructor is declared with no arguments, therefore nothing is injected into `MyDirective`. + * Here the constructor is declared with no arguments, therefore nothing is injected into + * `MyDirective`. * * ``` * @Directive({ selector: '[my-directive]' }) @@ -115,9 +133,11 @@ import {DEFAULT} from 'angular2/change_detection'; * * ### Component-level injection * - * Directives can inject any injectable instance from the closest component injector or any of its parents. + * Directives can inject any injectable instance from the closest component injector or any of its + * parents. * - * Here, the constructor declares a parameter, `someService`, and injects the `SomeService` type from the parent + * Here, the constructor declares a parameter, `someService`, and injects the `SomeService` type + * from the parent * component's injector. * ``` * @Directive({ selector: '[my-directive]' }) @@ -142,13 +162,16 @@ import {DEFAULT} from 'angular2/change_detection'; * } * } * ``` - * This directive would be instantiated with `Dependency` declared at the same element, in this case `dependency="3"`. + * This directive would be instantiated with `Dependency` declared at the same element, in this case + * `dependency="3"`. * * * ### Injecting a directive from a direct parent element * - * Directives can inject other directives declared on a direct parent element. By definition, a directive with a - * `@Parent` annotation does not attempt to resolve dependencies for the current element, even if this would satisfy + * Directives can inject other directives declared on a direct parent element. By definition, a + * directive with a + * `@Parent` annotation does not attempt to resolve dependencies for the current element, even if + * this would satisfy * the dependency. * * ``` @@ -159,13 +182,16 @@ import {DEFAULT} from 'angular2/change_detection'; * } * } * ``` - * This directive would be instantiated with `Dependency` declared at the parent element, in this case `dependency="2"`. + * This directive would be instantiated with `Dependency` declared at the parent element, in this + * case `dependency="2"`. * * * ### Injecting a directive from any ancestor elements * - * Directives can inject other directives declared on any ancestor element (in the current Shadow DOM), i.e. on the - * parent element and its parents. By definition, a directive with an `@Ancestor` annotation does not attempt to + * Directives can inject other directives declared on any ancestor element (in the current Shadow + * DOM), i.e. on the + * parent element and its parents. By definition, a directive with an `@Ancestor` annotation does + * not attempt to * resolve dependencies for the current element, even if this would satisfy the dependency. * * ``` @@ -178,16 +204,19 @@ import {DEFAULT} from 'angular2/change_detection'; * ``` * * Unlike the `@Parent` which only checks the parent, `@Ancestor` checks the parent, as well as its - * parents recursively. If `dependency="2"` didn't exist on the direct parent, this injection would have returned + * parents recursively. If `dependency="2"` didn't exist on the direct parent, this injection would + * have returned * `dependency="1"`. * * * ### Injecting a live collection of direct child directives * * - * A directive can also query for other child directives. Since parent directives are instantiated before child + * A directive can also query for other child directives. Since parent directives are instantiated + * before child * directives, a directive can't simply inject the list of child directives. Instead, the directive - * injects a {@link QueryList}, which updates its contents as children are added, removed, or moved by a directive + * injects a {@link QueryList}, which updates its contents as children are added, removed, or moved + * by a directive * that uses a {@link ViewContainerRef} such as a `for`, an `if`, or a `switch`. * * ``` @@ -198,7 +227,8 @@ import {DEFAULT} from 'angular2/change_detection'; * } * ``` * - * This directive would be instantiated with a {@link QueryList} which contains `Dependency` 4 and 6. Here, `Dependency` + * This directive would be instantiated with a {@link QueryList} which contains `Dependency` 4 and + * 6. Here, `Dependency` * 5 would not be included, because it is not a direct child. * * ### Injecting a live collection of descendant directives @@ -219,9 +249,12 @@ import {DEFAULT} from 'angular2/change_detection'; * * ### Optional injection * - * The normal behavior of directives is to return an error when a specified dependency cannot be resolved. If you - * would like to inject `null` on unresolved dependency instead, you can annotate that dependency with `@Optional()`. - * This explicitly permits the author of a template to treat some of the surrounding directives as optional. + * The normal behavior of directives is to return an error when a specified dependency cannot be + * resolved. If you + * would like to inject `null` on unresolved dependency instead, you can annotate that dependency + * with `@Optional()`. + * This explicitly permits the author of a template to treat some of the surrounding directives as + * optional. * * ``` * @Directive({ selector: '[my-directive]' }) @@ -231,7 +264,8 @@ import {DEFAULT} from 'angular2/change_detection'; * } * ``` * - * This directive would be instantiated with a `Dependency` directive found on the current element. If none can be + * This directive would be instantiated with a `Dependency` directive found on the current element. + * If none can be * found, the injector supplies `null` instead of throwing an error. * * ## Example @@ -269,24 +303,31 @@ import {DEFAULT} from 'angular2/change_detection'; * } * } * ``` - * In our HTML template, we can then add this behavior to a `
` or any other element with the `tooltip` selector, + * In our HTML template, we can then add this behavior to a `
` or any other element with the + * `tooltip` selector, * like so: * * ``` *
* ``` * - * Directives can also control the instantiation, destruction, and positioning of inline template elements: + * Directives can also control the instantiation, destruction, and positioning of inline template + * elements: * - * A directive uses a {@link ViewContainerRef} to instantiate, insert, move, and destroy views at runtime. - * The {@link ViewContainerRef} is created as a result of `