I wrote a basic angular application that uses the EventEmitter class, however I cannot get the listening component to catch the event.
Here is my code (using alpha.27 on Angular2 / TypeScript 1.5 compiling on ES5) Sorry for the detailed example.
Any advice on what I am doing wrong would be very helpful.
import {Component, View, EventEmitter} from 'angular2/angular2'; @Component({ selector: 'login', events : ['loggedIn'] }) @View({ template: '<button type="button" (click)="submitForm()">Click Me</button>' }) export class Login { loggedIn = new EventEmitter(); constructor() { } submitForm() { console.log("event fired"); this.loggedIn.next({}); } } @Component({ selector: 'app' }) @View({ template: "<div>This is the application</div>" }) export class App { constructor() { } } @Component({ selector: 'root' }) @View({ template: '<app [hidden]=!showApp></app><login (loggedIn)="loggedIn()" [hidden]=showApp></login>', directives: [ App, Login ] }) export class Root { showApp:boolean; constructor() { this.showApp = false; } loggedIn() { console.log("event caught"); this.showApp = true; } }
Daylight programmer
source share