docs(core): add docs to Property and Event
This commit is contained in:
parent
ef61b81b0c
commit
ce6b364dc5
|
@ -454,17 +454,7 @@ export interface PipeFactory {
|
||||||
/**
|
/**
|
||||||
* {@link PropertyMetadata} factory for creating decorators.
|
* {@link PropertyMetadata} factory for creating decorators.
|
||||||
*
|
*
|
||||||
* ## Example as TypeScript Decorator
|
* See {@link PropertyMetadata}.
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* @Directive({
|
|
||||||
* selector: 'sample-dir'
|
|
||||||
* })
|
|
||||||
* class SampleDir {
|
|
||||||
* @Property() property; // Same as @Property('property') property;
|
|
||||||
* @Property("el-property") dirProperty;
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*/
|
*/
|
||||||
export interface PropertyFactory {
|
export interface PropertyFactory {
|
||||||
(bindingPropertyName?: string): any;
|
(bindingPropertyName?: string): any;
|
||||||
|
@ -474,17 +464,7 @@ export interface PropertyFactory {
|
||||||
/**
|
/**
|
||||||
* {@link EventMetadata} factory for creating decorators.
|
* {@link EventMetadata} factory for creating decorators.
|
||||||
*
|
*
|
||||||
* ## Example as TypeScript Decorator
|
* See {@link EventMetadata}.
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* @Directive({
|
|
||||||
* selector: 'sample-dir'
|
|
||||||
* })
|
|
||||||
* class SampleDir {
|
|
||||||
* @Event() event = new EventEmitter(); // Same as @Event('event') event = new EventEmitter();
|
|
||||||
* @Event("el-event") dirEvent = new EventEmitter();
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*/
|
*/
|
||||||
export interface EventFactory {
|
export interface EventFactory {
|
||||||
(bindingPropertyName?: string): any;
|
(bindingPropertyName?: string): any;
|
||||||
|
@ -588,11 +568,15 @@ export var Pipe: PipeFactory = <PipeFactory>makeDecorator(PipeMetadata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link PropertyMetadata} factory function.
|
* {@link PropertyMetadata} factory function.
|
||||||
|
*
|
||||||
|
* See {@link PropertyMetadata}.
|
||||||
*/
|
*/
|
||||||
export var Property: PropertyFactory = makePropDecorator(PropertyMetadata);
|
export var Property: PropertyFactory = makePropDecorator(PropertyMetadata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EventMetadata} factory function.
|
* {@link EventMetadata} factory function.
|
||||||
|
*
|
||||||
|
* See {@link EventMetadata}.
|
||||||
*/
|
*/
|
||||||
export var Event: EventFactory = makePropDecorator(EventMetadata);
|
export var Event: EventFactory = makePropDecorator(EventMetadata);
|
||||||
|
|
||||||
|
|
|
@ -417,7 +417,9 @@ export class DirectiveMetadata extends InjectableMetadata {
|
||||||
selector: string;
|
selector: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumerates the set of properties that accept data binding for a directive.
|
* Enumerates the set of data-bound properties for a directive
|
||||||
|
*
|
||||||
|
* Angular automatically updates data-bound properties during change detection.
|
||||||
*
|
*
|
||||||
* The `properties` property defines a set of `directiveProperty` to `bindingProperty`
|
* The `properties` property defines a set of `directiveProperty` to `bindingProperty`
|
||||||
* configuration:
|
* configuration:
|
||||||
|
@ -425,108 +427,88 @@ export class DirectiveMetadata extends InjectableMetadata {
|
||||||
* - `directiveProperty` specifies the component property where the value is written.
|
* - `directiveProperty` specifies the component property where the value is written.
|
||||||
* - `bindingProperty` specifies the DOM property where the value is read from.
|
* - `bindingProperty` specifies the DOM property where the value is read from.
|
||||||
*
|
*
|
||||||
* You can include a {@link PipeMetadata} when specifying a `bindingProperty` to allow for data
|
* When `bindingProperty` is not provided, it is assumed to be equal to `directiveProperty`.
|
||||||
* transformation and structural change detection of the value. These pipes will be evaluated in
|
|
||||||
* the context of this component.
|
|
||||||
*
|
*
|
||||||
* ## Syntax
|
* ### Example ([live demo](http://plnkr.co/edit/ivhfXY?p=preview))
|
||||||
*
|
*
|
||||||
* There is no need to specify both `directiveProperty` and `bindingProperty` when they both have
|
* The following example creates a component with two data-bound properties.
|
||||||
* the same value.
|
|
||||||
*
|
*
|
||||||
* ```
|
* ```typescript
|
||||||
* @Directive({
|
* @Component({
|
||||||
* properties: [
|
* selector: 'bank-account',
|
||||||
* 'propertyName', // shorthand notation for 'propertyName: propertyName'
|
* properties: ['bankName', 'id: account-id']
|
||||||
* 'directiveProperty1: bindingProperty1',
|
|
||||||
* 'directiveProperty2: bindingProperty2 | pipe1 | ...',
|
|
||||||
* ...
|
|
||||||
* ]
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* ## Basic Property Binding
|
|
||||||
*
|
|
||||||
* We can easily build a simple `Tooltip` directive that exposes a `tooltip` property, which can
|
|
||||||
* be used in templates with standard Angular syntax. For example:
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* @Directive({
|
|
||||||
* selector: '[tooltip]',
|
|
||||||
* properties: [
|
|
||||||
* 'text: tooltip'
|
|
||||||
* ]
|
|
||||||
* })
|
* })
|
||||||
* class Tooltip {
|
* @View({
|
||||||
* set text(value: string) {
|
* template: `
|
||||||
* // This will get called every time with the new value when the 'tooltip' property changes
|
* Bank Name: {{bankName}}
|
||||||
|
* Account Id: {{id}}
|
||||||
|
* `
|
||||||
|
* })
|
||||||
|
* class BankAccount {
|
||||||
|
* bankName: string;
|
||||||
|
* id: string;
|
||||||
|
*
|
||||||
|
* // this property is not bound, and won't be automatically updated by Angular
|
||||||
|
* normalizedBankName: string;
|
||||||
* }
|
* }
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
*
|
||||||
* We can then bind to the `tooltip' property as either an expression (`someExpression`) or as a
|
* @Component({selector: 'app'})
|
||||||
* string literal, as shown in the HTML template below:
|
* @View({
|
||||||
|
* template: `
|
||||||
|
* <bank-account bank-name="RBC" account-id="4747"></bank-account>
|
||||||
|
* `,
|
||||||
|
* directives: [BankAccount]
|
||||||
|
* })
|
||||||
|
* class App {}
|
||||||
*
|
*
|
||||||
* ```html
|
* bootstrap(App);
|
||||||
* <div [tooltip]="someExpression">...</div>
|
|
||||||
* <div tooltip="Some Text">...</div>
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* Whenever the `someExpression` expression changes, the `properties` declaration instructs
|
|
||||||
* Angular to update the `Tooltip`'s `text` property.
|
|
||||||
*
|
|
||||||
* ### Bindings With Pipes
|
|
||||||
*
|
|
||||||
* You can use pipes in bindings, as follows:
|
|
||||||
*
|
|
||||||
* ```html
|
|
||||||
* <div [class-set]="someExpression | somePipe">
|
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
properties: string[];
|
properties: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enumerates the set of emitted events.
|
* Enumerates the set of event-bound properties.
|
||||||
*
|
*
|
||||||
* ## Syntax
|
* When an event-bound property emits an event, an event handler attached to that event
|
||||||
|
* the template is invoked.
|
||||||
*
|
*
|
||||||
* ```
|
* The `events` property defines a set of `directiveProperty` to `bindingProperty`
|
||||||
* @Component({
|
* configuration:
|
||||||
* events: ['statusChange']
|
*
|
||||||
|
* - `directiveProperty` specifies the component property that emits events.
|
||||||
|
* - `bindingProperty` specifies the DOM property the event handler is attached to.
|
||||||
|
*
|
||||||
|
* ### Example ([live demo](http://plnkr.co/edit/d5CNq7?p=preview))
|
||||||
|
*
|
||||||
|
* ```typescript
|
||||||
|
* @Directive({
|
||||||
|
* selector: 'interval-dir',
|
||||||
|
* events: ['everySecond', 'five5Secs: everyFiveSeconds']
|
||||||
* })
|
* })
|
||||||
* class TaskComponent {
|
* class IntervalDir {
|
||||||
* statusChange: EventEmitter;
|
* everySecond = new EventEmitter();
|
||||||
|
* five5Secs = new EventEmitter();
|
||||||
*
|
*
|
||||||
* constructor() {
|
* constructor() {
|
||||||
* this.statusChange = new EventEmitter();
|
* setInterval(() => this.everySecond.next("event"), 1000);
|
||||||
* }
|
* setInterval(() => this.five5Secs.next("event"), 5000);
|
||||||
*
|
|
||||||
* onComplete() {
|
|
||||||
* this.statusChange.next('completed');
|
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
* ```
|
|
||||||
*
|
*
|
||||||
* Use `propertyName: eventName` when the event emitter property name is different from the name
|
* @Component({selector: 'app'})
|
||||||
* of the emitted event:
|
* @View({
|
||||||
*
|
* template: `
|
||||||
* ```
|
* <interval-dir (every-second)="everySecond()" (every-five-seconds)="everyFiveSeconds()">
|
||||||
* @Component({
|
* </interval-dir>
|
||||||
* events: ['status: statusChange']
|
* `,
|
||||||
|
* directives: [IntervalDir]
|
||||||
* })
|
* })
|
||||||
* class TaskComponent {
|
* class App {
|
||||||
* status: EventEmitter;
|
* everySecond() { console.log('second'); }
|
||||||
*
|
* everyFiveSeconds() { console.log('five seconds'); }
|
||||||
* constructor() {
|
|
||||||
* this.status = new EventEmitter();
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* onComplete() {
|
|
||||||
* this.status.next('completed');
|
|
||||||
* }
|
|
||||||
* }
|
* }
|
||||||
|
* bootstrap(App);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -940,38 +922,94 @@ export class PipeMetadata extends InjectableMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare a bound field.
|
* Declares a data-bound property.
|
||||||
*
|
*
|
||||||
* ## Example
|
* Angular automatically updates data-bound properties during change detection.
|
||||||
*
|
*
|
||||||
* ```
|
* `PropertyMetadata` takes an optional parameters that specifies that name
|
||||||
* @Directive({
|
* used when instantiating a component in the template. When not provided,
|
||||||
* selector: 'sample-dir'
|
* the class property name is used.
|
||||||
|
*
|
||||||
|
* ### Example
|
||||||
|
*
|
||||||
|
* The following example creates a component with two data-bound properties.
|
||||||
|
*
|
||||||
|
* ```typescript
|
||||||
|
* @Component({selector: 'bank-account'})
|
||||||
|
* @View({
|
||||||
|
* template: `
|
||||||
|
* Bank Name: {{bankName}}
|
||||||
|
* Account Id: {{id}}
|
||||||
|
* `
|
||||||
* })
|
* })
|
||||||
* class SampleDir {
|
* class BankAccount {
|
||||||
* @Property() property; // Same as @Property('property') property;
|
* @Property() bankName: string;
|
||||||
* @Property("el-property") dirProperty;
|
* @Property('account-id') id: string;
|
||||||
|
*
|
||||||
|
* // this property is not bound, and won't be automatically updated by Angular
|
||||||
|
* normalizedBankName: string;
|
||||||
* }
|
* }
|
||||||
|
*
|
||||||
|
* @Component({selector: 'app'})
|
||||||
|
* @View({
|
||||||
|
* template: `
|
||||||
|
* <bank-account bank-name="RBC" account-id="4747"></bank-account>
|
||||||
|
* `,
|
||||||
|
* directives: [BankAccount]
|
||||||
|
* })
|
||||||
|
* class App {}
|
||||||
|
*
|
||||||
|
* bootstrap(App);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
export class PropertyMetadata {
|
export class PropertyMetadata {
|
||||||
constructor(public bindingPropertyName?: string) {}
|
constructor(
|
||||||
|
/**
|
||||||
|
* Name used when instantiating a component in the temlate.
|
||||||
|
*/
|
||||||
|
public bindingPropertyName?: string) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare a bound event.
|
* Declares an event-bound property.
|
||||||
*
|
*
|
||||||
* ## Example
|
* When an event-bound property emits an event, an event handler attached to that event
|
||||||
|
* the template is invoked.
|
||||||
*
|
*
|
||||||
* ```
|
* `EventMetadata` takes an optional parameters that specifies that name
|
||||||
|
* used when instantiating a component in the template. When not provided,
|
||||||
|
* the class property name is used.
|
||||||
|
*
|
||||||
|
* ### Example
|
||||||
|
*
|
||||||
|
* ```typescript
|
||||||
* @Directive({
|
* @Directive({
|
||||||
* selector: 'sample-dir'
|
* selector: 'interval-dir',
|
||||||
* })
|
* })
|
||||||
* class SampleDir {
|
* class IntervalDir {
|
||||||
* @Event() event = new EventEmitter(); // Same as @Event('event') event = new EventEmitter();
|
* @Event() everySecond = new EventEmitter();
|
||||||
* @Event("el-event") dirEvent = new EventEmitter();
|
* @Event('everyFiveSeconds') five5Secs = new EventEmitter();
|
||||||
|
*
|
||||||
|
* constructor() {
|
||||||
|
* setInterval(() => this.everySecond.next("event"), 1000);
|
||||||
|
* setInterval(() => this.five5Secs.next("event"), 5000);
|
||||||
* }
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* @Component({selector: 'app'})
|
||||||
|
* @View({
|
||||||
|
* template: `
|
||||||
|
* <interval-dir (every-second)="everySecond()" (every-five-seconds)="everyFiveSeconds()">
|
||||||
|
* </interval-dir>
|
||||||
|
* `,
|
||||||
|
* directives: [IntervalDir]
|
||||||
|
* })
|
||||||
|
* class App {
|
||||||
|
* everySecond() { console.log('second'); }
|
||||||
|
* everyFiveSeconds() { console.log('five seconds'); }
|
||||||
|
* }
|
||||||
|
* bootstrap(App);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@CONST()
|
@CONST()
|
||||||
|
@ -980,9 +1018,11 @@ export class EventMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare a host property binding.
|
* Declares a host binding property.
|
||||||
*
|
*
|
||||||
* ## Example
|
* Angular automatically updates data-bound properties during change detection.
|
||||||
|
*
|
||||||
|
* ### Example
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* @Directive({
|
* @Directive({
|
||||||
|
|
Loading…
Reference in New Issue