Last active
December 4, 2015 14:36
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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