UNPKG

1.83 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Subject } from 'rxjs/Subject';
9/**
10 * Use by directives and components to emit custom Events.
11 *
12 * ### Examples
13 *
14 * In the following example, `Zippy` alternatively emits `open` and `close` events when its
15 * title gets clicked:
16 *
17 * ```
18 * @Component({
19 * selector: 'zippy',
20 * template: `
21 * <div class="zippy">
22 * <div (click)="toggle()">Toggle</div>
23 * <div [hidden]="!visible">
24 * <ng-content></ng-content>
25 * </div>
26 * </div>`})
27 * export class Zippy {
28 * visible: boolean = true;
29 * @Output() open: EventEmitter<any> = new EventEmitter();
30 * @Output() close: EventEmitter<any> = new EventEmitter();
31 *
32 * toggle() {
33 * this.visible = !this.visible;
34 * if (this.visible) {
35 * this.open.emit(null);
36 * } else {
37 * this.close.emit(null);
38 * }
39 * }
40 * }
41 * ```
42 *
43 * The events payload can be accessed by the parameter `$event` on the components output event
44 * handler:
45 *
46 * ```
47 * <zippy (open)="onOpen($event)" (close)="onClose($event)"></zippy>
48 * ```
49 *
50 * Uses Rx.Observable but provides an adapter to make it work as specified here:
51 * https://github.com/jhusain/observable-spec
52 *
53 * Once a reference implementation of the spec is available, switch to it.
54 * @stable
55 */
56export declare class EventEmitter<T> extends Subject<T> {
57 __isAsync: boolean;
58 /**
59 * Creates an instance of [EventEmitter], which depending on [isAsync],
60 * delivers events synchronously or asynchronously.
61 */
62 constructor(isAsync?: boolean);
63 emit(value?: T): void;
64 subscribe(generatorOrNext?: any, error?: any, complete?: any): any;
65}