Working with Angular2s forms and trying to figure out the process of handling events with selects. I have an object Heros that is stored in the options. What I want to do is that when I hero is selected, trigger an event to the parent component that will do something with the results. However, I can't find a concrete example of being able to receive an event when the selection has changed (ie a new hero in the list as been selected).
interface Hero {
id: number;
name: string;
}
@Component({
selector: 'my-app',
template:`
<h1>{{title}}</h1>
<form>
<select>
<option *ngFor="#hero of heros "
[value]="hero">
{{hero .name}}
</option>
</select>
</form>
`
})
export class AppComponent {
@Input() heros:Observable<Hero>
@Output("selectedHeroChange") selectedHeroChange:EventEmitter<any> = new EventEmitter
onHeroChange(hero:Hero){
this.selectedHeroChange._next(hero);
}
}
Thanks in advance!