Angular 2 version used: 2.0.0-alpha.44
I am trying to emit a Output signal from a component. I followed the Angular docs here .Below is the code of my component
@Component({
    selector: 'summary'
})
@View({
    directives: [NgFor, NgIf, ROUTER_DIRECTIVES, LogoutComponent, BarChartDirective, SunburstChartDirective],
    templateUrl: 'view/summary-component.html'
})
export class SummaryComponent {
    @Output() loadSummary: EventEmitter = new EventEmitter();
    project: Project;
    data: any;
    constructor(public http: Http,
            public router: Router,
            public xxxGlobalService: XXXGlobalService) {
        console.log("SummaryComponent: Created");
        this.getSummary()  
    }
    getSummary() {
        this.project = this.xxxGlobalService.getOpenedProject();
        var url = "/project_summary?username="+ this.xxxGlobalService.getUser().name + "&project_id=" + this.project.id;
        this.http.get(url)
                 .map(res => res.json())
                 .subscribe(
                     data => this.extractData(data),
                     err => this.logError(err),
                () => console.log('SummaryComponent: Successfully got the summary')
        );
    }
    extractData(data) {
        this.data = data;
        console.log("SummaryComponent: Emitting loadSummary event");
        this.loadSummary.next("event");
    }
}
However i get error saying "TypeError: router_1.EventEmitter is not a function" when i try to allocate the EventEmitter (below line)
@Output() loadSummary: EventEmitter = new EventEmitter();
I checked the link and modified the line to look like
@Output() loadSummary: EventEmitter;
But the loadSummary seems to be undefined throughout. How to emit the output signal ? Please help
As of beta.0 (and maybe earlier), EventEmitter is now in angular2/core.
Emit an event using emit():
@Output() loadSummary: EventEmitter<any> = new EventEmitter();
...
this.loadSummary.emit("event");
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With