Angular 2 Copy Event

Angular 2 copy event using the EventEmitter, a mother component receives the copy event from the child component when a user copies the content of an element.

angular 2 copy example
angular 2 copy example

Try it yourself,Live Example

try angular 2 copy
try angular 2 copy
/**
 * Created by Tareq Boulakjar. from angulartypescript.com
 */
import {Component,EventEmitter,Output} from 'angular2/core';

/*Child Component Will (Send or Emit) a Copy Event */
@Component({
    selector: 'event-emitter-copy-com',
    template:`
                <h2>EventEmitter on Copy</h2>
                <input type="text" value="Do Copy Action To See" (copy)="eventEmitCopy($event)" class="event-emitter-copy-component-style"/>

    `,
    styles:[`
            .event-emitter-copy-component-style {
              width: 200px;
              background-color:#00AA00;
              color: white;
             }

         `]
})
class EventEmitterCopyComponent {
    @Output() eventEmitterCopy = new EventEmitter();

    eventEmitCopy(event) {
        this.eventEmitterCopy.emit(event);
    }

}
/*Mother is the receiver of the event */

@Component({
    selector: 'event-emitter-copy',
    template: `
                <event-emitter-copy-com (eventEmitterCopy)="receiveEvent($event)" >
                </event-emitter-copy-com>
               `,
    directives: [EventEmitterCopyComponent]

})
export class EventEmitterCopyExample {
    receiveEvent(event) { console.log('Copy event from angulartypescript.com.'); console.log(event);  }
}

Our example uses Typescript as programming language.

Done !