To download events, go to this article , starting with the beginners error # 2.
For general events, I found that EventEmitter is useful as a way for child components (native markup labels) to inform the parent component of the child events. In the child case, create a custom event (a class variable decorated with @Output() ) that will be .emit() whenever you define, and you can include the parameters of your EventEmitter specified by <data type> . Then the parent can process the custom event and access the parameters that you invested in $event . I am using Angular 2 quick launch file.
Baby Script:
import {Component, Output, EventEmitter} from '@angular/core'; @Component({ selector: 'my-child', templateUrl: 'app/my-child.component.html' }) export class MyChildComponent { @Output() childReadyEvent: EventEmitter<string> = new EventEmitter(); ngOnInit(){
Parental Markup:
<h3>I'm the parent</h3> <my-child (childReadyEvent)="parentHandlingFcn($event)"></my-child>
Parent Script:
import {Component} from '@angular/core'; import {MyChildComponent} from './my-child.component'; @Component({ selector: 'my-parent', templateUrl: 'app/my-parent.component.html', directives: [MyChildComponent] }) export class MyParentComponent { ngOnInit(){ console.log("this executes first"); } parentHandlingFcn(receivedParam: string) { console.log("this executes third, with " + receivedParam);
Note. You can also try EventEmitter<MyChildComponent> with .emit(this)
BeatriceThalo
source share