Skip to content

Commit

Permalink
feat(playground): add examples with EventEmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Apr 20, 2016
1 parent 9c6170e commit c977ff5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
4 changes: 4 additions & 0 deletions playground/app/components/todo-app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export class TodoAppCmp{
this.items.push(newId);
}

outputWithEmitReceiver( sentence: string ) {
console.log( sentence );
}


directive = {
example: {
Expand Down
6 changes: 4 additions & 2 deletions playground/app/components/todo-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ <h3>Todo List remaining: {{ $ctrl.todos | remainingTodos }}</h3>

<todo-item
todo="item"
on-done="$ctrl.markAsDone(todo)"
idx="$index">
on-done="$ctrl.markAsDone($event)"
emit-test="$ctrl.outputWithEmitReceiver($event)"
idx="$index"
>
<button
ng-click="$ctrl.removeTodo(item)"
class="mdl-button mdl-js-button mdl-button--accent">
Expand Down
22 changes: 18 additions & 4 deletions playground/app/components/todo-item.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, Output, OnChanges } from 'ng-metadata/core';
import { Component, Input, Output, OnChanges, EventEmitter } from 'ng-metadata/core';
import { TodoModel } from '../stores/todoStore.service';

@Component({
Expand All @@ -12,9 +12,19 @@ export class TodoItemCmp implements OnChanges{

@Input('<') todo: TodoModel;
@Input('<') idx: number;
@Output() onDone: ( todo: {todo:TodoModel} )=>void;
// this is old way how to bindings are created, will be removed in 2.0
// @Output() onDone: ( todo: {todo:TodoModel} )=>void;
@Output() onDone: EventEmitter<TodoModel>;
@Output() emitTest = new EventEmitter<string>();

ngOnInit(){}
ngOnInit(){

const dispose = this.onDone.subscribe( (value)=> {
console.log( `onDone emitted value: ${value}` );
dispose();
} )

}

ngOnChanges(change){
console.log('changes:', change);
Expand All @@ -27,9 +37,13 @@ export class TodoItemCmp implements OnChanges{

}

callEmit(){
this.emitTest.emit( 'hello from eventEmitter instance!' );
}

done(todo: TodoModel) {

this.onDone( { todo } );
this.onDone.emit( todo );

}

Expand Down
2 changes: 1 addition & 1 deletion playground/app/components/todo-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="mdl-checkbox__input"
ng-model="$ctrl.todo.complete"
ng-change="$ctrl.done($ctrl.todo)">
<span class="mdl-checkbox__label">{{ $ctrl.todo.label }}</span>
<span class="mdl-checkbox__label" ng-click="$ctrl.callEmit()">{{ $ctrl.todo.label }}</span>

</label>
<ng-transclude></ng-transclude>
10 changes: 10 additions & 0 deletions playground/ng-metadata.legacy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,16 @@ declare module ngMetadataCore{
* unidirectional data flow).
*/
export function enableProdMode(): void;

export class EventEmitter<T> {
/**
* Creates an instance of [EventEmitter], which depending on [isAsync],
* delivers events synchronously or asynchronously.
*/
constructor(isAsync?: boolean);
emit(value: T): void;
subscribe(generatorOrNext?: Function, error?: any, complete?: any): Function;
}
}

declare module ngMetadataCommon {
Expand Down

0 comments on commit c977ff5

Please sign in to comment.