Skip to content

Instantly share code, notes, and snippets.

@kadmil
Last active December 4, 2015 14:36
Show Gist options
  • Save kadmil/ecd9e808866aa8512e2f to your computer and use it in GitHub Desktop.
Save kadmil/ecd9e808866aa8512e2f to your computer and use it in GitHub Desktop.
Angular2 (2.0.0-alpha.44) pass parameters from your own component event (look at template for parent)
import {Component} from 'angular2/angular2'
@Component({
selector: 'child',
template: '<div (click)='passNumber.next(num)'/>',
})
export default class Login {
public num: number = 1
@Output() passNumber = new EventEmitter()
}
import {Component} from 'angular2/angular2'
import Child from './child.ts'
// $event param is the key here — without it nothing is passed to callback
@Component({
selector: 'parent',
template: '<child (pass-number)='callback($event)'/>',
directives: [Child],
})
export default class Login {
public callback: Function
constructor(){
this.callback = num => console.log(num)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment