diff --git a/aio/content/guide/ngmodule-api.md b/aio/content/guide/ngmodule-api.md
index e661cad113..5e11305445 100644
--- a/aio/content/guide/ngmodule-api.md
+++ b/aio/content/guide/ngmodule-api.md
@@ -12,8 +12,8 @@ A basic understanding of the following concepts:
At a high level, NgModules are a way to organize Angular apps
and they accomplish this through the metadata in the `@NgModule`
-decorator. The metadata falls
-into three categories:
+decorator.
+The metadata falls into three categories:
* **Static:** Compiler configuration which tells the compiler about directive selectors and where in templates the directives should be applied through selector matching. This is configured via the `declarations` array.
* **Runtime:** Injector configuration via the `providers` array.
@@ -75,9 +75,8 @@ The following table summarizes the `@NgModule` metadata properties.
Components, directives, and pipes must belong to _exactly_ one module.
- The compiler emits an error if you try to declare the same class in more than one module.
-
- Don't re-declare a class imported from another module.
+ The compiler emits an error if you try to declare the same class in more than one module. Be careful not to re-declare a class that is imported
+ directly or indirectly from another module.
@@ -108,7 +107,7 @@ The following table summarizes the `@NgModule` metadata properties.
Components in external modules continue to receive the instance provided by their injectors.
- For more information on injector hierarchy and scoping, see [Providers](guide/providers).
+ For more information on injector hierarchy and scoping, see [Providers](guide/providers) and the [DI Guide](guide/dependency-injection).
diff --git a/packages/core/src/change_detection/change_detector_ref.ts b/packages/core/src/change_detection/change_detector_ref.ts
index 2c50ff96aa..ffe982f003 100644
--- a/packages/core/src/change_detection/change_detector_ref.ts
+++ b/packages/core/src/change_detection/change_detector_ref.ts
@@ -6,179 +6,101 @@
* found in the LICENSE file at https://angular.io/license
*/
+/**
+ * Base class for Angular Views, provides change detection functionality.
+ * A change-detection tree collects all views that are to be checked for changes.
+ * Use the methods to add and remove views from the tree, initiate change-detection,
+ * and exlicitly mark views as _dirty_, meaning that they have changed and need to be rerendered.
+ *
+ * @usageNotes
+ *
+ * The following examples demonstrate how to modify default change-detection behavior
+ * to perform explicit detection when needed.
+ *
+ * ### Use `markForCheck()` with `checkOnce` strategy
+ *
+ * The following example sets the `OnPush` change-detection strategy for a component
+ * (`checkOnce`, rather than the default `checkAlways`), then forces a second check
+ * after an interval. See [live demo](http://plnkr.co/edit/GC512b?p=preview).
+ *
+ *
+ *
+ * ### Detach change detector to limit how often check occurs
+ *
+ * The following example defines a component with a large list of read-only data
+ * that is expected to change constantly, many times per second.
+ * To improve performance, we want to check and update the list
+ * less often than the changes actually occur. To do that, we detach
+ * the component's change detector and perform an explicit local check every five seconds.
+ *
+ *
+ *
+ *
+ * ### Reattaching a detached component
+ *
+ * The following example creates a component displaying live data.
+ * The component detaches its change detector from the main change detector tree
+ * when the `live` property is set to false, and reattaches it when the property
+ * becomes true.
+ *
+ *
+ *
+ */
export abstract class ChangeDetectorRef {
/**
- * Marks a view and all of its ancestors dirty.
+ * When a view uses the {@link ChangeDetectionStrategy#OnPush OnPush} (checkOnce)
+ * change detection strategy, explicitly marks the view as changed so that
+ * it can be checked again.
*
- * This can be used to ensure an {@link ChangeDetectionStrategy#OnPush OnPush} component is
- * checked when it needs to be re-rendered but the two normal triggers haven't marked it
- * dirty (i.e. inputs haven't changed and events haven't fired in the view).
+ * Components are normally marked as dirty (in need of rerendering) when inputs
+ * have changed or events have fired in the view. Call this method to ensure that
+ * a component is checked even if these triggers have not occured.
*
*
*
- * @usageNotes
- * ### Example
- *
- * ```typescript
- * @Component({
- * selector: 'my-app',
- * template: `Number of ticks: {{numberOfTicks}}`
- * changeDetection: ChangeDetectionStrategy.OnPush,
- * })
- * class AppComponent {
- * numberOfTicks = 0;
- *
- * constructor(private ref: ChangeDetectorRef) {
- * setInterval(() => {
- * this.numberOfTicks++;
- * // the following is required, otherwise the view will not be updated
- * this.ref.markForCheck();
- * }, 1000);
- * }
- * }
- * ```
*/
abstract markForCheck(): void;
/**
- * Detaches the view from the change detection tree.
+ * Detaches this view from the change-detection tree.
+ * A detached view is not checked until it is reattached.
+ * Use in combination with `detectChanges()` to implement local change detection checks.
*
- * Detached views will not be checked during change detection runs until they are
- * re-attached, even if they are dirty. `detach` can be used in combination with
- * {@link ChangeDetectorRef#detectChanges detectChanges} to implement local change
- * detection checks.
+ * Detached views are not checked during change detection runs until they are
+ * re-attached, even if they are marked as dirty.
*
*
*
*
- * @usageNotes
- * ### Example
- *
- * The following example defines a component with a large list of readonly data.
- * Imagine the data changes constantly, many times per second. For performance reasons,
- * we want to check and update the list every five seconds. We can do that by detaching
- * the component's change detector and doing a local check every five seconds.
- *
- * ```typescript
- * class DataProvider {
- * // in a real application the returned data will be different every time
- * get data() {
- * return [1,2,3,4,5];
- * }
- * }
- *
- * @Component({
- * selector: 'giant-list',
- * template: `
- *
Data {{d}}
- * `,
- * })
- * class GiantList {
- * constructor(private ref: ChangeDetectorRef, private dataProvider: DataProvider) {
- * ref.detach();
- * setInterval(() => {
- * this.ref.detectChanges();
- * }, 5000);
- * }
- * }
- *
- * @Component({
- * selector: 'app',
- * providers: [DataProvider],
- * template: `
- *
- * `,
- * })
- * class App {
- * }
- * ```
*/
abstract detach(): void;
/**
- * Checks the view and its children.
- *
- * This can also be used in combination with {@link ChangeDetectorRef#detach detach} to implement
- * local change detection checks.
+ * Checks this view and its children. Use in combination with {@link ChangeDetectorRef#detach
+ * detach}
+ * to implement local change detection checks.
*
*
*
*
- * @usageNotes
- *
- * Imagine, the data changes constantly, many times per second. For performance reasons,
- * we want to check and update the list every five seconds.
- *
- * We can do that by detaching the component's change detector and doing a local change detection
- * check every five seconds.
- *
- * See {@link ChangeDetectorRef#detach detach} for more information.
*/
abstract detectChanges(): void;
/**
* Checks the change detector and its children, and throws if any changes are detected.
*
- * This is used in development mode to verify that running change detection doesn't introduce
+ * Use in development mode to verify that running change detection doesn't introduce
* other changes.
*/
abstract checkNoChanges(): void;
/**
- * Re-attaches the view to the change detection tree.
- *
- * This can be used to re-attach views that were previously detached from the tree
- * using {@link ChangeDetectorRef#detach detach}. Views are attached to the tree by default.
+ * Re-attaches the previously detached view to the change detection tree.
+ * Views are attached to the tree by default.
*
*
*
- * @usageNotes
- * ### Example
- *
- * The following example creates a component displaying `live` data. The component will detach
- * its change detector from the main change detector tree when the component's live property
- * is set to false.
- *
- * ```typescript
- * class DataProvider {
- * data = 1;
- *
- * constructor() {
- * setInterval(() => {
- * this.data = this.data * 2;
- * }, 500);
- * }
- * }
- *
- * @Component({
- * selector: 'live-data',
- * inputs: ['live'],
- * template: 'Data: {{dataProvider.data}}'
- * })
- * class LiveData {
- * constructor(private ref: ChangeDetectorRef, private dataProvider: DataProvider) {}
- *
- * set live(value) {
- * if (value) {
- * this.ref.reattach();
- * } else {
- * this.ref.detach();
- * }
- * }
- * }
- *
- * @Component({
- * selector: 'my-app',
- * providers: [DataProvider],
- * template: `
- * Live Update:
- *
- * `,
- * })
- * class AppComponent {
- * live = true;
- * }
- * ```
*/
abstract reattach(): void;
}
diff --git a/packages/core/src/change_detection/constants.ts b/packages/core/src/change_detection/constants.ts
index 6add5fc6b2..3713b0f5a5 100644
--- a/packages/core/src/change_detection/constants.ts
+++ b/packages/core/src/change_detection/constants.ts
@@ -8,63 +8,74 @@
/**
- * Describes within the change detector which strategy will be used the next time change
- * detection is triggered.
+ * The strategy that the default change detector uses to detect changes.
+ * When set, takes effect the next time change detection is triggered.
*
*/
export enum ChangeDetectionStrategy {
/**
- * `OnPush` means that the change detector's mode will be initially set to `CheckOnce`.
+ * Use the `CheckOnce` strategy, meaning that automatic change detection is deactivated
+ * until reactivated by setting the strategy to `Default` (`CheckAlways`).
+ * Change detection can still be explictly invoked.
*/
OnPush = 0,
/**
- * `Default` means that the change detector's mode will be initially set to `CheckAlways`.
+ * Use the default `CheckAlways` strategy, in which change detection is automatic until
+ * explicitly deactivated.
*/
Default = 1,
}
/**
- * Describes the status of the detector.
+ * Defines the possible states of the default change detector.
+ * @see `ChangeDetectorRef`
*/
export enum ChangeDetectorStatus {
/**
- * `CheckOnce` means that after calling detectChanges the mode of the change detector
- * will become `Checked`.
+ * A state in which, after calling `detectChanges()`, the change detector
+ * state becomes `Checked`, and must be explicitly invoked or reactivated.
*/
CheckOnce,
/**
- * `Checked` means that the change detector should be skipped until its mode changes to
- * `CheckOnce`.
+ * A state in which change detection is skipped until the change detector mode
+ * becomes `CheckOnce`.
*/
Checked,
/**
- * `CheckAlways` means that after calling detectChanges the mode of the change detector
- * will remain `CheckAlways`.
+ * A state in which change detection continues automatically until explictly
+ * deactivated.
*/
CheckAlways,
/**
- * `Detached` means that the change detector sub tree is not a part of the main tree and
+ * A state in which a change detector sub tree is not a part of the main tree and
* should be skipped.
*/
Detached,
/**
- * `Errored` means that the change detector encountered an error checking a binding
+ * Indicates that the change detector encountered an error checking a binding
* or calling a directive lifecycle method and is now in an inconsistent state. Change
- * detectors in this state will no longer detect changes.
+ * detectors in this state do not detect changes.
*/
Errored,
/**
- * `Destroyed` means that the change detector is destroyed.
+ * Indicates that the change detector has been destroyed.
*/
Destroyed,
}
+/**
+ * Reports whether a given strategy is currently the default for change detection.
+ * @param changeDetectionStrategy The strategy to check.
+ * @returns True if the given strategy is the current default, false otherwise.
+ * @see `ChangeDetectorStatus`
+ * @see `ChangeDetectorRef`
+ */
export function isDefaultChangeDetectionStrategy(changeDetectionStrategy: ChangeDetectionStrategy):
boolean {
return changeDetectionStrategy == null ||
diff --git a/packages/core/src/di/metadata.ts b/packages/core/src/di/metadata.ts
index ac10a47402..8198c9d0ea 100644
--- a/packages/core/src/di/metadata.ts
+++ b/packages/core/src/di/metadata.ts
@@ -18,19 +18,19 @@ import {EMPTY_ARRAY} from '../view/util';
*/
export interface InjectDecorator {
/**
- * A parameter decorator that specifies a dependency.
+ * A constructor parameter decorator that specifies a
+ * custom provider of a dependency.
*
- * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
+ * @see ["Dependency Injection Guide"](guide/dependency-injection).
*
* @usageNotes
- * ### Example
+ * The following example shows a class constructor that specifies a
+ * custom provider of a dependency using the parameter decorator.
*
* {@example core/di/ts/metadata_spec.ts region='Inject'}
*
- * When `@Inject()` is not present, `Injector` will use the type annotation of the
- * parameter.
- *
- * ### Example
+ * When `@Inject()` is not present, the `Injector` uses the type annotation of the
+ * parameter as the provider.
*
* {@example core/di/ts/metadata_spec.ts region='InjectWithoutDecorator'}
*/
@@ -41,7 +41,12 @@ export interface InjectDecorator {
/**
* Type of the Inject metadata.
*/
-export interface Inject { token: any; }
+export interface Inject {
+ /**
+ * Injector token that maps to the dependency to be injected.
+ */
+ token: any;
+}
/**
* Inject decorator and metadata.
@@ -56,15 +61,14 @@ export const Inject: InjectDecorator = makeParamDecorator('Inject', (token: any)
*/
export interface OptionalDecorator {
/**
- * A parameter metadata that marks a dependency as optional.
- * `Injector` provides `null` if the dependency is not found.
+ * A constructor parameter decorator that marks a dependency as optional.
*
- * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
- *
- * @usageNotes
- * ### Example
+ * The DI framework provides null if the dependency is not found.
+ * For example, the following code allows the possibility of a null result:
*
* {@example core/di/ts/metadata_spec.ts region='Optional'}
+ *
+ * @see ["Dependency Injection Guide"](guide/dependency-injection).
*/
(): any;
new (): Optional;
@@ -87,14 +91,18 @@ export const Optional: OptionalDecorator = makeParamDecorator('Optional');
*/
export interface SelfDecorator {
/**
- * Specifies that an `Injector` should retrieve a dependency only from itself.
+ * A constructor parameter decorator that tells the DI framework
+ * to retrieve a dependency only from the local injector.
*
- * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
- *
- * @usageNotes
- * ### Example
+ * In the following example, the dependency can be resolved
+ * by the local injector when instantiating the class itself, but not
+ * when instantiating a child.
*
* {@example core/di/ts/metadata_spec.ts region='Self'}
+ *
+ * @see ["Dependency Injection Guide"](guide/dependency-injection).
+ *
+ *
*/
(): any;
new (): Self;
@@ -118,14 +126,17 @@ export const Self: SelfDecorator = makeParamDecorator('Self');
*/
export interface SkipSelfDecorator {
/**
- * Specifies that the dependency resolution should start from the parent injector.
+ * A constructor parameter decorator that tells the DI framework
+ * that dependency resolution should start from the parent injector.
*
- * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
- *
- * @usageNotes
- * ### Example
+ * In the following example, the dependency can be resolved when
+ * instantiating a child, but not when instantiating the class itself.
*
* {@example core/di/ts/metadata_spec.ts region='SkipSelf'}
+ *
+ * @see ["Dependency Injection Guide"](guide/dependency-injection).
+ *
+ *
*/
(): any;
new (): SkipSelf;
@@ -150,13 +161,13 @@ export const SkipSelf: SkipSelfDecorator = makeParamDecorator('SkipSelf');
*/
export interface HostDecorator {
/**
- * Specifies that an injector should retrieve a dependency from any injector until
+ * A constructor parameter decorator that tells the DI framework
+ * to retrieve a dependency from any injector until
* reaching the host element of the current component.
*
- * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
+ * @see ["Dependency Injection Guide"](guide/dependency-injection).
*
- * @usageNotes
- * ### Example
+ * @usageNotes
*
* {@example core/di/ts/metadata_spec.ts region='Host'}
*/
diff --git a/packages/core/src/event_emitter.ts b/packages/core/src/event_emitter.ts
index 582bb61fb6..1e5368e88e 100644
--- a/packages/core/src/event_emitter.ts
+++ b/packages/core/src/event_emitter.ts
@@ -9,13 +9,15 @@
import {Subject, Subscription} from 'rxjs';
/**
- * Use by directives and components to emit custom Events.
+ * Use in directives and components to emit custom events synchronously
+ * or asynchronously, and register handlers for those events by subscribing
+ * to an instance.
*
* @usageNotes
- * ### Examples
*
- * In the following example, `Zippy` alternatively emits `open` and `close` events when its
- * title gets clicked:
+ * In the following example, a component defines two output properties
+ * that create event emitters. When the title is clicked, the emitter
+ * emits an open or close event to toggle the current visibility state.
*
* ```
* @Component({
@@ -43,7 +45,7 @@ import {Subject, Subscription} from 'rxjs';
* }
* ```
*
- * The events payload can be accessed by the parameter `$event` on the components output event
+ * Access the event object with the `$event` argument passed to the output event
* handler:
*
* ```
@@ -63,23 +65,37 @@ export class EventEmitter extends Subject {
// we can't mark it as internal now because EventEmitter exported via @angular/core would not
// contain this property making it incompatible with all the code that uses EventEmitter via
// facades, which are local to the code and do not have this property stripped.
- // tslint:disable-next-line
- __isAsync: boolean;
+ /**
+ * Internal
+ */
+ __isAsync: boolean; // tslint:disable-line
/**
- * Creates an instance of {@link EventEmitter}, which depending on `isAsync`,
- * delivers events synchronously or asynchronously.
+ * Creates an instance of this class that can
+ * deliver events synchronously or asynchronously.
+ *
+ * @param isAsync When true, deliver events asynchronously.
*
- * @param isAsync By default, events are delivered synchronously (default value: `false`).
- * Set to `true` for asynchronous event delivery.
*/
constructor(isAsync: boolean = false) {
super();
this.__isAsync = isAsync;
}
+ /**
+ * Emits an event containing a given value.
+ * @param value The value to emit.
+ */
emit(value?: T) { super.next(value); }
+ /**
+ * Registers handlers for events emitted by this instance.
+ * @param generatorOrNext When supplied, a custom handler for emitted events.
+ * @param error When supplied, a custom handler for an error notification
+ * from this emitter.
+ * @param complete When supplied, a custom handler for a completion
+ * notification from this emitter.
+ */
subscribe(generatorOrNext?: any, error?: any, complete?: any): any {
let schedulerFn: (t: any) => any;
let errorFn = (err: any): any => null;
diff --git a/packages/core/src/metadata/di.ts b/packages/core/src/metadata/di.ts
index d25a9a52fa..c568bbdf18 100644
--- a/packages/core/src/metadata/di.ts
+++ b/packages/core/src/metadata/di.ts
@@ -309,11 +309,10 @@ export const ViewChildren: ViewChildrenDecorator = makePropDecorator(
export interface ViewChildDecorator {
/**
* @description
- * Configures a view query.
- *
- * You can use ViewChild to get the first element or the directive matching the selector from the
- * view DOM. If the view DOM changes, and a new child matches the selector,
- * the property will be updated.
+ * Property decorator that configures a view query.
+ * The change detector looks for the first element or the directive matching the selector
+ * in the view DOM. If the view DOM changes, and a new child matches the selector,
+ * the property is updated.
*
* View queries are set before the `ngAfterViewInit` callback is called.
*
diff --git a/packages/core/src/metadata/directives.ts b/packages/core/src/metadata/directives.ts
index 0784cef48b..e1e8a296f0 100644
--- a/packages/core/src/metadata/directives.ts
+++ b/packages/core/src/metadata/directives.ts
@@ -19,37 +19,18 @@ import {ViewEncapsulation} from './view';
*/
export interface DirectiveDecorator {
/**
- * Marks a class as an Angular directive and collects directive configuration
- * metadata.
- *
- * Directive decorator allows you to mark a class as an Angular directive and provide additional
- * metadata that determines how the directive should be processed, instantiated and used at
+ * Marks a class as an Angular directive. You can define your own
+ * directives to attach custom behavior to elements in the DOM.
+ * The options provide configuration metadata that determines
+ * how the directive should be processed, instantiated and used at
* runtime.
*
- * Directives allow you to attach behavior to elements in the DOM..
+ * Directive classes, like component classes, can implement
+ * [life-cycle hoooks](guide/lifecycle-hooks) to influence their configuration and behavior.
*
- * A directive must belong to an NgModule in order for it to be usable
- * by another directive, component, or application. To specify that a directive is a member of an
- * NgModule,
- * you should list it in the `declarations` field of that NgModule.
- *
- * In addition to the metadata configuration specified via the Directive decorator,
- * directives can control their runtime behavior by implementing various Life-Cycle hooks.
- *
- * **Metadata Properties:**
- *
- * * **exportAs** - name under which the component instance is exported in a template. Can be
- * given a single name or a comma-delimited list of names.
- * * **host** - map of class property to host element bindings for events, properties and
- * attributes
- * * **inputs** - list of class property names to data-bind as component inputs
- * * **outputs** - list of class property names that expose output events that others can
- * subscribe to
- * * **providers** - list of providers available to this component and its children
- * * **queries** - configure queries that can be injected into the component
- * * **selector** - css selector that identifies this component in a template
*
* @usageNotes
+ * To define a directive, mark the class with the decorator and provide metadata.
*
* ```
* import {Directive} from '@angular/core';
@@ -58,9 +39,27 @@ export interface DirectiveDecorator {
* selector: 'my-directive',
* })
* export class MyDirective {
+ * ...
* }
* ```
*
+ * ### Declaring directives
+ *
+ * Directives are [declarables](guide/glossary#declarable).
+ * Like component and pipes, they must be declared by an NgModule
+ * in order to be usable in an app.
+ *
+ * A directive must belong to exactly one NgModule. Do not re-declare
+ * a directive imported from another module.
+ * List the directive class in the `declarations` field of an NgModule.
+ *
+ * ```
+ * declarations: [
+ * AppComponent,
+ * MyDirective
+ * ],
+ * ```
+ *
* @Annotation
*/
(obj: Directive): TypeDecorator;
@@ -75,10 +74,7 @@ export interface Directive {
/**
* The CSS selector that triggers the instantiation of a directive.
*
- * Angular only allows directives to trigger on CSS selectors that do not cross element
- * boundaries.
- *
- * `selector` may be declared as one of the following:
+ * Declare as one of the following:
*
* - `element-name`: select by element name.
* - `.class`: select by class name.
@@ -87,12 +83,10 @@ export interface Directive {
* - `:not(sub_selector)`: select only if the element does not match the `sub_selector`.
* - `selector1, selector2`: select if either `selector1` or `selector2` matches.
*
- * @usageNotes
- * ### Example
- *
- * Suppose we have a directive with an `input[type=text]` selector.
- *
- * And the following HTML:
+ * Angular only allows directives to trigger on CSS selectors that do not cross element
+ * boundaries. For example, consider a directive with an `input[type=text]` selector.
+ * For the following HTML, the directive is instantiated only on the
+ * `` element.
*
* ```html
*